Update gjson and fix golint messages

This commit is contained in:
tidwall 2021-09-01 20:12:27 -07:00
parent 7fd8b8e83c
commit a2a89c2f1e
4 changed files with 25 additions and 11 deletions

4
go.mod
View File

@ -3,6 +3,6 @@ module github.com/tidwall/sjson
go 1.14 go 1.14
require ( require (
github.com/tidwall/gjson v1.8.0 github.com/tidwall/gjson v1.9.0
github.com/tidwall/pretty v1.1.0 github.com/tidwall/pretty v1.2.0
) )

7
go.sum
View File

@ -1,6 +1,7 @@
github.com/tidwall/gjson v1.8.0 h1:Qt+orfosKn0rbNTZqHYDqBrmm3UDA4KRkv70fDzG+PQ= github.com/tidwall/gjson v1.9.0 h1:+Od7AE26jAaMgVC31cQV/Ope5iKXulNMflrlB7k+F9E=
github.com/tidwall/gjson v1.8.0/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk= 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 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= 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.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=

View File

@ -3,7 +3,6 @@ package sjson
import ( import (
jsongo "encoding/json" jsongo "encoding/json"
"reflect"
"strconv" "strconv"
"unsafe" "unsafe"
@ -489,6 +488,17 @@ func DeleteBytes(json []byte, path string) ([]byte, error) {
return SetBytes(json, path, dtype{}) 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, func set(jstr, path, raw string,
stringify, del, optimistic, inplace bool) ([]byte, error) { stringify, del, optimistic, inplace bool) ([]byte, error) {
if path == "" { if path == "" {
@ -503,9 +513,9 @@ func set(jstr, path, raw string,
} }
if inplace && sz <= len(jstr) { if inplace && sz <= len(jstr) {
if !stringify || !mustMarshalString(raw) { if !stringify || !mustMarshalString(raw) {
jsonh := *(*reflect.StringHeader)(unsafe.Pointer(&jstr)) jsonh := *(*stringHeader)(unsafe.Pointer(&jstr))
jsonbh := reflect.SliceHeader{ jsonbh := sliceHeader{
Data: jsonh.Data, Len: jsonh.Len, Cap: jsonh.Len} data: jsonh.data, len: jsonh.len, cap: jsonh.len}
jbytes := *(*[]byte)(unsafe.Pointer(&jsonbh)) jbytes := *(*[]byte)(unsafe.Pointer(&jsonbh))
if stringify { if stringify {
jbytes[res.Index] = '"' jbytes[res.Index] = '"'
@ -571,8 +581,8 @@ func SetOptions(json, path string, value interface{},
opts.ReplaceInPlace = false opts.ReplaceInPlace = false
} }
} }
jsonh := *(*reflect.StringHeader)(unsafe.Pointer(&json)) jsonh := *(*stringHeader)(unsafe.Pointer(&json))
jsonbh := reflect.SliceHeader{Data: jsonh.Data, Len: jsonh.Len} jsonbh := sliceHeader{data: jsonh.data, len: jsonh.len, cap: jsonh.len}
jsonb := *(*[]byte)(unsafe.Pointer(&jsonbh)) jsonb := *(*[]byte)(unsafe.Pointer(&jsonbh))
res, err := SetBytesOptions(jsonb, path, value, opts) res, err := SetBytesOptions(jsonb, path, value, opts)
return string(res), err return string(res), err

View File

@ -334,3 +334,6 @@ func TestIssue36(t *testing.T) {
t.Fatal("unexpected result") t.Fatal("unexpected result")
} }
} }
func TestIndexes(t *testing.T) {
}