From a2a89c2f1eaac50bf8f57ffffc860735d9f5d55a Mon Sep 17 00:00:00 2001 From: tidwall Date: Wed, 1 Sep 2021 20:12:27 -0700 Subject: [PATCH] Update gjson and fix golint messages --- go.mod | 4 ++-- go.sum | 7 ++++--- sjson.go | 22 ++++++++++++++++------ sjson_test.go | 3 +++ 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index bf16920..e231e58 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module github.com/tidwall/sjson go 1.14 require ( - github.com/tidwall/gjson v1.8.0 - github.com/tidwall/pretty v1.1.0 + github.com/tidwall/gjson v1.9.0 + github.com/tidwall/pretty v1.2.0 ) diff --git a/go.sum b/go.sum index 72eee42..6b06bcf 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,7 @@ -github.com/tidwall/gjson v1.8.0 h1:Qt+orfosKn0rbNTZqHYDqBrmm3UDA4KRkv70fDzG+PQ= -github.com/tidwall/gjson v1.8.0/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk= +github.com/tidwall/gjson v1.9.0 h1:+Od7AE26jAaMgVC31cQV/Ope5iKXulNMflrlB7k+F9E= +github.com/tidwall/gjson v1.9.0/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk= github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE= github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= -github.com/tidwall/pretty v1.1.0 h1:K3hMW5epkdAVwibsQEfR/7Zj0Qgt4DxtNumTq/VloO8= github.com/tidwall/pretty v1.1.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= diff --git a/sjson.go b/sjson.go index 3c1ae11..8724177 100644 --- a/sjson.go +++ b/sjson.go @@ -3,7 +3,6 @@ package sjson import ( jsongo "encoding/json" - "reflect" "strconv" "unsafe" @@ -489,6 +488,17 @@ func DeleteBytes(json []byte, path string) ([]byte, error) { return SetBytes(json, path, dtype{}) } +type stringHeader struct { + data unsafe.Pointer + len int +} + +type sliceHeader struct { + data unsafe.Pointer + len int + cap int +} + func set(jstr, path, raw string, stringify, del, optimistic, inplace bool) ([]byte, error) { if path == "" { @@ -503,9 +513,9 @@ func set(jstr, path, raw string, } if inplace && sz <= len(jstr) { if !stringify || !mustMarshalString(raw) { - jsonh := *(*reflect.StringHeader)(unsafe.Pointer(&jstr)) - jsonbh := reflect.SliceHeader{ - Data: jsonh.Data, Len: jsonh.Len, Cap: jsonh.Len} + jsonh := *(*stringHeader)(unsafe.Pointer(&jstr)) + jsonbh := sliceHeader{ + data: jsonh.data, len: jsonh.len, cap: jsonh.len} jbytes := *(*[]byte)(unsafe.Pointer(&jsonbh)) if stringify { jbytes[res.Index] = '"' @@ -571,8 +581,8 @@ func SetOptions(json, path string, value interface{}, opts.ReplaceInPlace = false } } - jsonh := *(*reflect.StringHeader)(unsafe.Pointer(&json)) - jsonbh := reflect.SliceHeader{Data: jsonh.Data, Len: jsonh.Len} + jsonh := *(*stringHeader)(unsafe.Pointer(&json)) + jsonbh := sliceHeader{data: jsonh.data, len: jsonh.len, cap: jsonh.len} jsonb := *(*[]byte)(unsafe.Pointer(&jsonbh)) res, err := SetBytesOptions(jsonb, path, value, opts) return string(res), err diff --git a/sjson_test.go b/sjson_test.go index 318e565..407d8ca 100644 --- a/sjson_test.go +++ b/sjson_test.go @@ -334,3 +334,6 @@ func TestIssue36(t *testing.T) { t.Fatal("unexpected result") } } + +func TestIndexes(t *testing.T) { +}