summaryrefslogtreecommitdiff
path: root/encode.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-02-16 22:56:11 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-02-16 22:56:11 -0700
commit6f8e7db1ac5ddd21b8e3fcc39a1e30fde9b62c3a (patch)
tree8f0247b646291577f54f7d164b7fed675388c72c /encode.go
parentdebef01cc500fb9368e1d6d0206a32ca358a8c98 (diff)
parent0d23080e1f2af81d8d4656c3b72791b26f52f361 (diff)
Merge branch 'lukeshu/perf'
Diffstat (limited to 'encode.go')
-rw-r--r--encode.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/encode.go b/encode.go
index 2e10134..38a2e93 100644
--- a/encode.go
+++ b/encode.go
@@ -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 {