forked from mirror/go-json
Remove anonymous operation
This commit is contained in:
parent
6034aea48a
commit
1342fd2042
|
@ -2,7 +2,6 @@ package json_test
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/goccy/go-json"
|
||||
|
@ -1841,7 +1840,6 @@ func TestCoverArray(t *testing.T) {
|
|||
for _, test := range tests {
|
||||
for _, indent := range []bool{false} {
|
||||
for _, htmlEscape := range []bool{false} {
|
||||
fmt.Println(test.name)
|
||||
var buf bytes.Buffer
|
||||
enc := json.NewEncoder(&buf)
|
||||
enc.SetEscapeHTML(htmlEscape)
|
||||
|
|
|
@ -1765,8 +1765,8 @@ func TestCoverInt(t *testing.T) {
|
|||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
for _, indent := range []bool{true, false} {
|
||||
for _, htmlEscape := range []bool{true, false} {
|
||||
for _, indent := range []bool{false} {
|
||||
for _, htmlEscape := range []bool{false} {
|
||||
var buf bytes.Buffer
|
||||
enc := json.NewEncoder(&buf)
|
||||
enc.SetEscapeHTML(htmlEscape)
|
||||
|
|
|
@ -2,7 +2,6 @@ package json_test
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/goccy/go-json"
|
||||
|
@ -1841,7 +1840,6 @@ func TestCoverSlice(t *testing.T) {
|
|||
for _, test := range tests {
|
||||
for _, indent := range []bool{false} {
|
||||
for _, htmlEscape := range []bool{false} {
|
||||
fmt.Println(test.name)
|
||||
var buf bytes.Buffer
|
||||
enc := json.NewEncoder(&buf)
|
||||
enc.SetEscapeHTML(htmlEscape)
|
||||
|
|
|
@ -386,10 +386,9 @@ func encodeMarshalJSON(b []byte, v interface{}) ([]byte, error) {
|
|||
}
|
||||
|
||||
func encodeMarshalText(b []byte, v interface{}) ([]byte, error) {
|
||||
rv := reflect.ValueOf(v)
|
||||
bytes, err := rv.Interface().(encoding.TextMarshaler).MarshalText()
|
||||
bytes, err := v.(encoding.TextMarshaler).MarshalText()
|
||||
if err != nil {
|
||||
return nil, &MarshalerError{Type: rv.Type(), Err: err}
|
||||
return nil, &MarshalerError{Type: reflect.TypeOf(v), Err: err}
|
||||
}
|
||||
return encodeNoEscapedString(b, *(*string)(unsafe.Pointer(&bytes))), nil
|
||||
}
|
||||
|
|
|
@ -1083,7 +1083,7 @@ func encodeAnonymousStructFieldPairMap(tags structTags, named string, valueCode
|
|||
if existsKey {
|
||||
f.op = opStructFieldAnonymousHead
|
||||
} else if named == "" {
|
||||
f.op = op
|
||||
//f.op = op
|
||||
}
|
||||
} else if named == "" && f.op == opStructEnd {
|
||||
f.op = opStructAnonymousEnd
|
||||
|
@ -1325,6 +1325,9 @@ func encodeCompileStruct(ctx *encodeCompileContext, isPtr bool) (*opcode, error)
|
|||
anonymousFields[k] = append(anonymousFields[k], v...)
|
||||
}
|
||||
}
|
||||
if field.Anonymous {
|
||||
valueCode.anonymousHead = true
|
||||
}
|
||||
key := fmt.Sprintf(`"%s":`, tag.key)
|
||||
escapedKey := fmt.Sprintf(`%s:`, string(encodeEscapedString([]byte{}, tag.key)))
|
||||
valueCode.indirect = indirect
|
||||
|
|
|
@ -18,6 +18,7 @@ type opcode struct {
|
|||
displayKey string // key text to display
|
||||
isTaggedKey bool // whether tagged key
|
||||
anonymousKey bool // whether anonymous key
|
||||
anonymousHead bool // whether anonymous head or not
|
||||
root bool // whether root
|
||||
indirect bool // whether indirect or not
|
||||
nilcheck bool // whether needs to nilcheck or not
|
||||
|
@ -92,6 +93,7 @@ func (c *opcode) copy(codeMap map[uintptr]*opcode) *opcode {
|
|||
rshiftNum: c.rshiftNum,
|
||||
isTaggedKey: c.isTaggedKey,
|
||||
anonymousKey: c.anonymousKey,
|
||||
anonymousHead: c.anonymousHead,
|
||||
root: c.root,
|
||||
indirect: c.indirect,
|
||||
nilcheck: c.nilcheck,
|
||||
|
|
1947
encode_vm.go
1947
encode_vm.go
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue