diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-16 22:56:11 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-16 22:56:11 -0700 |
commit | 6f8e7db1ac5ddd21b8e3fcc39a1e30fde9b62c3a (patch) | |
tree | 8f0247b646291577f54f7d164b7fed675388c72c /encode.go | |
parent | debef01cc500fb9368e1d6d0206a32ca358a8c98 (diff) | |
parent | 0d23080e1f2af81d8d4656c3b72791b26f52f361 (diff) |
Merge branch 'lukeshu/perf'
Diffstat (limited to 'encode.go')
-rw-r--r-- | encode.go | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -228,7 +228,12 @@ func encode(w *ReEncoder, val reflect.Value, escaper BackslashEscaper, quote boo return err } } - if _, err := w.WriteString(strconv.FormatInt(val.Int(), 10)); err != nil { + // MaxInt64 = 9223372036854775807 + // MinInt64 = -9223372036854775808 + // 0 1 2 + // 12345678901234567890 + var buf [20]byte + if _, err := w.Write(strconv.AppendInt(buf[:0], val.Int(), 10)); err != nil { return err } if quote { @@ -242,7 +247,11 @@ func encode(w *ReEncoder, val reflect.Value, escaper BackslashEscaper, quote boo return err } } - if _, err := w.WriteString(strconv.FormatUint(val.Uint(), 10)); err != nil { + // MaxUint64 = 18446744073709551615 + // 0 1 2 + // 12345678901234567890 + var buf [20]byte + if _, err := w.Write(strconv.AppendUint(buf[:0], val.Uint(), 10)); err != nil { return err } if quote { |