forked from mirror/sjson
Update gjson and fix golint messages
This commit is contained in:
parent
7fd8b8e83c
commit
a2a89c2f1e
4
go.mod
4
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
|
||||
)
|
||||
|
|
7
go.sum
7
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=
|
||||
|
|
22
sjson.go
22
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
|
||||
|
|
|
@ -334,3 +334,6 @@ func TestIssue36(t *testing.T) {
|
|||
t.Fatal("unexpected result")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIndexes(t *testing.T) {
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue