1
0
mirror of https://github.com/json-iterator/go.git synced 2025-07-09 23:45:32 +02:00

Unmarshalling float with lots of digits can cause >= 2 allocations per number

We can fix this with a little bit of scratch space.
This commit is contained in:
Phil Pearl
2022-02-14 11:09:22 +00:00
parent 024077e996
commit e79221c6f6
4 changed files with 74 additions and 11 deletions

View File

@ -10,7 +10,8 @@ import (
func Benchmark_stream_encode_big_object(b *testing.B) {
var buf bytes.Buffer
var stream = jsoniter.NewStream(jsoniter.ConfigDefault, &buf, 100)
stream := jsoniter.NewStream(jsoniter.ConfigDefault, &buf, 100)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
buf.Reset()
stream.Reset(&buf)
@ -22,13 +23,13 @@ func Benchmark_stream_encode_big_object(b *testing.B) {
}
func TestEncodeObject(t *testing.T) {
var stream = jsoniter.NewStream(jsoniter.ConfigDefault, nil, 100)
stream := jsoniter.NewStream(jsoniter.ConfigDefault, nil, 100)
encodeObject(stream)
if stream.Error != nil {
t.Errorf("error encoding a test object: %+v", stream.Error)
return
}
var m = make(map[string]interface{})
m := make(map[string]interface{})
if err := jsoniter.Unmarshal(stream.Buffer(), &m); err != nil {
t.Errorf("error unmarshaling a test object: %+v", err)
return