Remove anonymous operation

This commit is contained in:
Masaaki Goshima 2021-03-06 12:51:09 +09:00
parent 6034aea48a
commit 1342fd2042
7 changed files with 670 additions and 1927 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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
}

View File

@ -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

View File

@ -9,21 +9,22 @@ import (
const uintptrSize = 4 << (^uintptr(0) >> 63) // unsafe.Sizeof(uintptr(0)) but an ideal const
type opcode struct {
op opType // operation type
typ *rtype // go type
displayIdx int // opcode index
key []byte // struct field key
escapedKey []byte // struct field key ( HTML escaped )
ptrNum int // pointer number: e.g. double pointer is 2.
displayKey string // key text to display
isTaggedKey bool // whether tagged key
anonymousKey bool // whether anonymous key
root bool // whether root
indirect bool // whether indirect or not
nilcheck bool // whether needs to nilcheck or not
rshiftNum uint8 // use to take bit for judging whether negative integer or not
mask uint64 // mask for number
indent int // indent number
op opType // operation type
typ *rtype // go type
displayIdx int // opcode index
key []byte // struct field key
escapedKey []byte // struct field key ( HTML escaped )
ptrNum int // pointer number: e.g. double pointer is 2.
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
rshiftNum uint8 // use to take bit for judging whether negative integer or not
mask uint64 // mask for number
indent int // indent number
idx uintptr // offset to access ptr
headIdx uintptr // offset to access slice/struct head
@ -81,29 +82,30 @@ func (c *opcode) copy(codeMap map[uintptr]*opcode) *opcode {
return code
}
copied := &opcode{
op: c.op,
typ: c.typ,
displayIdx: c.displayIdx,
key: c.key,
escapedKey: c.escapedKey,
displayKey: c.displayKey,
ptrNum: c.ptrNum,
mask: c.mask,
rshiftNum: c.rshiftNum,
isTaggedKey: c.isTaggedKey,
anonymousKey: c.anonymousKey,
root: c.root,
indirect: c.indirect,
nilcheck: c.nilcheck,
indent: c.indent,
idx: c.idx,
headIdx: c.headIdx,
elemIdx: c.elemIdx,
length: c.length,
mapIter: c.mapIter,
mapPos: c.mapPos,
offset: c.offset,
size: c.size,
op: c.op,
typ: c.typ,
displayIdx: c.displayIdx,
key: c.key,
escapedKey: c.escapedKey,
displayKey: c.displayKey,
ptrNum: c.ptrNum,
mask: c.mask,
rshiftNum: c.rshiftNum,
isTaggedKey: c.isTaggedKey,
anonymousKey: c.anonymousKey,
anonymousHead: c.anonymousHead,
root: c.root,
indirect: c.indirect,
nilcheck: c.nilcheck,
indent: c.indent,
idx: c.idx,
headIdx: c.headIdx,
elemIdx: c.elemIdx,
length: c.length,
mapIter: c.mapIter,
mapPos: c.mapPos,
offset: c.offset,
size: c.size,
}
codeMap[addr] = copied
copied.mapKey = c.mapKey.copy(codeMap)

File diff suppressed because it is too large Load Diff