forked from mirror/go-json
Merge branch 'goccy:master' into master
This commit is contained in:
commit
e94f0cd362
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
gojay "github.com/francoispqt/gojay"
|
||||
gojson "github.com/goccy/go-json"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
|
@ -33,6 +34,26 @@ func Benchmark_Decode_SmallStruct_Unmarshal_FastJson(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_SmallStruct_Unmarshal_SegmentioJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for n := 0; n < b.N; n++ {
|
||||
result := SmallPayload{}
|
||||
if err := segmentiojson.Unmarshal(SmallFixture, &result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_SmallStruct_Unmarshal_Sonic(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for n := 0; n < b.N; n++ {
|
||||
result := SmallPayload{}
|
||||
if err := sonic.Unmarshal(SmallFixture, &result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_SmallStruct_Unmarshal_JsonIter(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for n := 0; n < b.N; n++ {
|
||||
|
@ -63,16 +84,6 @@ func Benchmark_Decode_SmallStruct_Unmarshal_GoJayUnsafe(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_SmallStruct_Unmarshal_SegmentioJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for n := 0; n < b.N; n++ {
|
||||
result := SmallPayload{}
|
||||
if err := segmentiojson.Unmarshal(SmallFixture, &result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_SmallStruct_Unmarshal_GoJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
|
@ -105,6 +116,18 @@ func Benchmark_Decode_SmallStruct_Stream_EncodingJson(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_SmallStruct_Stream_SegmentioJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
reader := bytes.NewReader(SmallFixture)
|
||||
for i := 0; i < b.N; i++ {
|
||||
result := SmallPayload{}
|
||||
reader.Reset(SmallFixture)
|
||||
if err := segmentiojson.NewDecoder(reader).Decode(&result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_SmallStruct_Stream_JsonIter(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
reader := bytes.NewReader(SmallFixture)
|
||||
|
@ -129,18 +152,6 @@ func Benchmark_Decode_SmallStruct_Stream_GoJay(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_SmallStruct_Stream_SegmentioJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
reader := bytes.NewReader(SmallFixture)
|
||||
for i := 0; i < b.N; i++ {
|
||||
result := SmallPayload{}
|
||||
reader.Reset(SmallFixture)
|
||||
if err := segmentiojson.NewDecoder(reader).Decode(&result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_SmallStruct_Stream_GoJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
reader := bytes.NewReader(SmallFixture)
|
||||
|
@ -174,6 +185,26 @@ func Benchmark_Decode_MediumStruct_Unmarshal_FastJson(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_MediumStruct_Unmarshal_Sonic(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
result := MediumPayload{}
|
||||
if err := sonic.Unmarshal(MediumFixture, &result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_MediumStruct_Unmarshal_SegmentioJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
result := MediumPayload{}
|
||||
if err := segmentiojson.Unmarshal(MediumFixture, &result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_MediumStruct_Unmarshal_JsonIter(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for n := 0; n < b.N; n++ {
|
||||
|
@ -204,16 +235,6 @@ func Benchmark_Decode_MediumStruct_Unmarshal_GoJayUnsafe(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_MediumStruct_Unmarshal_SegmentioJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
result := MediumPayload{}
|
||||
if err := segmentiojson.Unmarshal(MediumFixture, &result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_MediumStruct_Unmarshal_GoJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
|
@ -246,6 +267,18 @@ func Benchmark_Decode_MediumStruct_Stream_EncodingJson(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_MediumStruct_Stream_SegmentioJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
reader := bytes.NewReader(MediumFixture)
|
||||
for n := 0; n < b.N; n++ {
|
||||
reader.Reset(MediumFixture)
|
||||
result := MediumPayload{}
|
||||
if err := segmentiojson.NewDecoder(reader).Decode(&result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_MediumStruct_Stream_JsonIter(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
reader := bytes.NewReader(MediumFixture)
|
||||
|
@ -270,18 +303,6 @@ func Benchmark_Decode_MediumStruct_Stream_GoJay(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_MediumStruct_Stream_SegmentioJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
reader := bytes.NewReader(MediumFixture)
|
||||
for n := 0; n < b.N; n++ {
|
||||
reader.Reset(MediumFixture)
|
||||
result := MediumPayload{}
|
||||
if err := segmentiojson.NewDecoder(reader).Decode(&result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_MediumStruct_Stream_GoJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
reader := bytes.NewReader(MediumFixture)
|
||||
|
@ -315,6 +336,26 @@ func Benchmark_Decode_LargeStruct_Unmarshal_FastJson(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_LargeStruct_Unmarshal_Sonic(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for n := 0; n < b.N; n++ {
|
||||
result := LargePayload{}
|
||||
if err := sonic.Unmarshal(LargeFixture, &result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_LargeStruct_Unmarshal_SegmentioJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
result := LargePayload{}
|
||||
if err := segmentiojson.Unmarshal(LargeFixture, &result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_LargeStruct_Unmarshal_JsonIter(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for n := 0; n < b.N; n++ {
|
||||
|
@ -345,16 +386,6 @@ func Benchmark_Decode_LargeStruct_Unmarshal_GoJayUnsafe(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_LargeStruct_Unmarshal_SegmentioJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
result := LargePayload{}
|
||||
if err := segmentiojson.Unmarshal(LargeFixture, &result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_LargeStruct_Unmarshal_GoJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
|
@ -415,6 +446,18 @@ func Benchmark_Decode_LargeStruct_Stream_EncodingJson(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_LargeStruct_Stream_SegmentioJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
reader := bytes.NewReader(LargeFixture)
|
||||
for i := 0; i < b.N; i++ {
|
||||
result := LargePayload{}
|
||||
reader.Reset(LargeFixture)
|
||||
if err := segmentiojson.NewDecoder(reader).Decode(&result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_LargeStruct_Stream_JsonIter(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
reader := bytes.NewReader(LargeFixture)
|
||||
|
@ -439,18 +482,6 @@ func Benchmark_Decode_LargeStruct_Stream_GoJay(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_LargeStruct_Stream_SegmentioJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
reader := bytes.NewReader(LargeFixture)
|
||||
for i := 0; i < b.N; i++ {
|
||||
result := LargePayload{}
|
||||
reader.Reset(LargeFixture)
|
||||
if err := segmentiojson.NewDecoder(reader).Decode(&result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_LargeStruct_Stream_GoJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
reader := bytes.NewReader(LargeFixture)
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
gojay "github.com/francoispqt/gojay"
|
||||
gojson "github.com/goccy/go-json"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
|
@ -77,6 +78,15 @@ func Benchmark_Encode_SmallStruct_SegmentioJson(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func Benchmark_Encode_SmallStruct_Sonic(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := sonic.Marshal(NewSmallPayload()); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Encode_SmallStruct_GoJsonColored(b *testing.B) {
|
||||
colorOpt := gojson.Colorize(gojson.DefaultColorScheme)
|
||||
b.ReportAllocs()
|
||||
|
@ -176,6 +186,16 @@ func Benchmark_Encode_SmallStructCached_SegmentioJson(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func Benchmark_Encode_SmallStructCached_Sonic(b *testing.B) {
|
||||
cached := NewSmallPayload()
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := sonic.Marshal(cached); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Encode_SmallStructCached_GoJsonColored(b *testing.B) {
|
||||
cached := NewSmallPayload()
|
||||
colorOpt := gojson.Colorize(gojson.DefaultColorScheme)
|
||||
|
@ -262,6 +282,15 @@ func Benchmark_Encode_MediumStruct_SegmentioJson(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func Benchmark_Encode_MediumStruct_Sonic(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := sonic.Marshal(NewMediumPayload()); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Encode_MediumStruct_GoJsonColored(b *testing.B) {
|
||||
colorOpt := gojson.Colorize(gojson.DefaultColorScheme)
|
||||
b.ReportAllocs()
|
||||
|
@ -351,6 +380,16 @@ func Benchmark_Encode_MediumStructCached_SegmentioJson(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func Benchmark_Encode_MediumStructCached_Sonic(b *testing.B) {
|
||||
cached := NewMediumPayload()
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := sonic.Marshal(cached); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Encode_MediumStructCached_GoJsonColored(b *testing.B) {
|
||||
cached := NewMediumPayload()
|
||||
colorOpt := gojson.Colorize(gojson.DefaultColorScheme)
|
||||
|
@ -437,6 +476,15 @@ func Benchmark_Encode_LargeStruct_SegmentioJson(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func Benchmark_Encode_LargeStruct_Sonic(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := sonic.Marshal(NewLargePayload()); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Encode_LargeStruct_GoJsonColored(b *testing.B) {
|
||||
colorOpt := gojson.Colorize(gojson.DefaultColorScheme)
|
||||
b.ReportAllocs()
|
||||
|
@ -526,6 +574,16 @@ func Benchmark_Encode_LargeStructCached_SegmentioJson(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func Benchmark_Encode_LargeStructCached_Sonic(b *testing.B) {
|
||||
cached := NewLargePayload()
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := sonic.Marshal(cached); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Encode_LargeStructCached_GoJsonColored(b *testing.B) {
|
||||
cached := NewLargePayload()
|
||||
colorOpt := gojson.Colorize(gojson.DefaultColorScheme)
|
||||
|
|
|
@ -3,9 +3,10 @@ module benchmark
|
|||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/bytedance/sonic v0.0.0-20210621033418-85a0d4219f94
|
||||
github.com/francoispqt/gojay v1.2.13
|
||||
github.com/goccy/go-json v0.0.0-00010101000000-000000000000
|
||||
github.com/json-iterator/go v1.1.9
|
||||
github.com/json-iterator/go v1.1.10
|
||||
github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe
|
||||
github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7
|
||||
github.com/segmentio/encoding v0.2.4
|
||||
|
|
|
@ -12,6 +12,10 @@ github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYU
|
|||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
|
||||
github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=
|
||||
github.com/bytedance/sonic v0.0.0-20210621033418-85a0d4219f94 h1:+PwepVHd43KuN9mFnAgB4962W/zuF/RGsM7B73Dyt+8=
|
||||
github.com/bytedance/sonic v0.0.0-20210621033418-85a0d4219f94/go.mod h1:+QewJQ2P8nkGhdzk5fHTSwRn03eDeJAbHWIlQnv95J4=
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20210528162528-3c6c11c43ee5 h1:7AStn2tanqGY99xzW+Ve1p6YYqnRr1m/yswJ4h0BhcY=
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20210528162528-3c6c11c43ee5/go.mod h1:NfDzX8KeqVNX62apij1OkqoeDdq1VR3g0TRZo99kkBA=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
|
@ -49,8 +53,12 @@ github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0
|
|||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
|
||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
|
||||
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/klauspost/cpuid/v2 v2.0.6 h1:dQ5ueTiftKxp0gyjKSx5+8BtPWkyQbd95m8Gys/RarI=
|
||||
github.com/klauspost/cpuid/v2 v2.0.6/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
|
@ -117,7 +125,13 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0
|
|||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
|
||||
github.com/tidwall/gjson v1.8.0/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk=
|
||||
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.1.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||
github.com/valyala/fastjson v1.6.3 h1:tAKFnnwmeMGPbwJ7IwxcTPCNr3uIzoIj3/Fh90ra4xc=
|
||||
github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
|
||||
github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU=
|
||||
|
@ -188,6 +202,7 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o=
|
||||
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package decoder
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"unsafe"
|
||||
|
||||
"github.com/goccy/go-json/internal/errors"
|
||||
|
@ -11,6 +12,7 @@ type mapDecoder struct {
|
|||
mapType *runtime.Type
|
||||
keyType *runtime.Type
|
||||
valueType *runtime.Type
|
||||
stringKeyType bool
|
||||
keyDecoder Decoder
|
||||
valueDecoder Decoder
|
||||
structName string
|
||||
|
@ -22,6 +24,7 @@ func newMapDecoder(mapType *runtime.Type, keyType *runtime.Type, keyDec Decoder,
|
|||
mapType: mapType,
|
||||
keyDecoder: keyDec,
|
||||
keyType: keyType,
|
||||
stringKeyType: keyType.Kind() == reflect.String,
|
||||
valueType: valueType,
|
||||
valueDecoder: valueDec,
|
||||
structName: structName,
|
||||
|
@ -32,9 +35,23 @@ func newMapDecoder(mapType *runtime.Type, keyType *runtime.Type, keyDec Decoder,
|
|||
//go:linkname makemap reflect.makemap
|
||||
func makemap(*runtime.Type, int) unsafe.Pointer
|
||||
|
||||
//nolint:golint
|
||||
//go:linkname mapassign_faststr runtime.mapassign_faststr
|
||||
//go:noescape
|
||||
func mapassign_faststr(t *runtime.Type, m unsafe.Pointer, s string) unsafe.Pointer
|
||||
|
||||
//go:linkname mapassign reflect.mapassign
|
||||
//go:noescape
|
||||
func mapassign(t *runtime.Type, m unsafe.Pointer, key, val unsafe.Pointer)
|
||||
func mapassign(t *runtime.Type, m unsafe.Pointer, k, v unsafe.Pointer)
|
||||
|
||||
func (d *mapDecoder) mapassign(t *runtime.Type, m, k, v unsafe.Pointer) {
|
||||
if d.stringKeyType {
|
||||
mapV := mapassign_faststr(d.mapType, m, *(*string)(k))
|
||||
typedmemmove(d.valueType, mapV, v)
|
||||
} else {
|
||||
mapassign(t, m, k, v)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *mapDecoder) DecodeStream(s *Stream, depth int64, p unsafe.Pointer) error {
|
||||
depth++
|
||||
|
@ -77,7 +94,7 @@ func (d *mapDecoder) DecodeStream(s *Stream, depth int64, p unsafe.Pointer) erro
|
|||
if err := d.valueDecoder.DecodeStream(s, depth, v); err != nil {
|
||||
return err
|
||||
}
|
||||
mapassign(d.mapType, mapValue, k, v)
|
||||
d.mapassign(d.mapType, mapValue, k, v)
|
||||
s.skipWhiteSpace()
|
||||
if s.equalChar('}') {
|
||||
**(**unsafe.Pointer)(unsafe.Pointer(&p)) = mapValue
|
||||
|
@ -141,7 +158,7 @@ func (d *mapDecoder) Decode(ctx *RuntimeContext, cursor, depth int64, p unsafe.P
|
|||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
mapassign(d.mapType, mapValue, k, v)
|
||||
d.mapassign(d.mapType, mapValue, k, v)
|
||||
cursor = skipWhiteSpace(buf, valueCursor)
|
||||
if buf[cursor] == '}' {
|
||||
**(**unsafe.Pointer)(unsafe.Pointer(&p)) = mapValue
|
||||
|
|
Loading…
Reference in New Issue