Fix pointer op

This commit is contained in:
Masaaki Goshima 2021-03-10 01:11:48 +09:00
parent d42d09f9f9
commit 37fb74bbb8
8 changed files with 628 additions and 2678 deletions

View File

@ -15,8 +15,6 @@ type opType struct {
Op string
Code string
HeadToPtrHead func() string
HeadToNPtrHead func() string
HeadToAnonymousHead func() string
HeadToOmitEmptyHead func() string
HeadToStringTagHead func() string
PtrHeadToHead func() string
@ -29,14 +27,6 @@ func (t opType) IsHeadToPtrHead() bool {
return t.Op != t.HeadToPtrHead()
}
func (t opType) IsHeadToNPtrHead() bool {
return t.Op != t.HeadToNPtrHead()
}
func (t opType) IsHeadToAnonymousHead() bool {
return t.Op != t.HeadToAnonymousHead()
}
func (t opType) IsHeadToOmitEmptyHead() bool {
return t.Op != t.HeadToOmitEmptyHead()
}
@ -66,8 +56,6 @@ func createOpType(op, code string) opType {
Op: op,
Code: code,
HeadToPtrHead: func() string { return op },
HeadToNPtrHead: func() string { return op },
HeadToAnonymousHead: func() string { return op },
HeadToOmitEmptyHead: func() string { return op },
HeadToStringTagHead: func() string { return op },
PtrHeadToHead: func() string { return op },
@ -121,19 +109,19 @@ func (t opType) codeType() codeType {
}
return codeStructField
}
if strings.Contains(t.String(), "ArrayHead") {
if t.String() == "Array" || t.String() == "ArrayPtr" {
return codeArrayHead
}
if strings.Contains(t.String(), "ArrayElem") {
return codeArrayElem
}
if strings.Contains(t.String(), "SliceHead") {
if t.String() == "Slice" || t.String() == "SlicePtr" {
return codeSliceHead
}
if strings.Contains(t.String(), "SliceElem") {
return codeSliceElem
}
if strings.Contains(t.String(), "MapHead") {
if t.String() == "Map" || t.String() == "MapPtr" {
return codeMapHead
}
if strings.Contains(t.String(), "MapKey") {
@ -153,9 +141,6 @@ func (t opType) headToPtrHead() opType {
if strings.Index(t.String(), "PtrHead") > 0 {
return t
}
if strings.Index(t.String(), "PtrAnonymousHead") > 0 {
return t
}
idx := strings.Index(t.String(), "Field")
if idx == -1 {
@ -163,42 +148,13 @@ func (t opType) headToPtrHead() opType {
}
suffix := "Ptr"+t.String()[idx+len("Field"):]
const toPtrOffset = 6
const toPtrOffset = 3
if strings.Contains(opType(int(t) + toPtrOffset).String(), suffix) {
return opType(int(t) + toPtrOffset)
}
return t
}
func (t opType) headToNPtrHead() opType {
if strings.Index(t.String(), "PtrHead") > 0 {
return t
}
if strings.Index(t.String(), "PtrAnonymousHead") > 0 {
return t
}
idx := strings.Index(t.String(), "Field")
if idx == -1 {
return t
}
suffix := "NPtr"+t.String()[idx+len("Field"):]
const toPtrOffset = 12
if strings.Contains(opType(int(t) + toPtrOffset).String(), suffix) {
return opType(int(t) + toPtrOffset)
}
return t
}
func (t opType) headToAnonymousHead() opType {
const toAnonymousOffset = 3
if strings.Contains(opType(int(t) + toAnonymousOffset).String(), "Anonymous") {
return opType(int(t) + toAnonymousOffset)
}
return t
}
func (t opType) headToOmitEmptyHead() opType {
const toOmitEmptyOffset = 1
if strings.Contains(opType(int(t) + toOmitEmptyOffset).String(), "OmitEmpty") {
@ -223,7 +179,7 @@ func (t opType) ptrHeadToHead() opType {
}
suffix := t.String()[idx+len("Ptr"):]
const toPtrOffset = 6
const toPtrOffset = 3
if strings.Contains(opType(int(t) - toPtrOffset).String(), suffix) {
return opType(int(t) - toPtrOffset)
}
@ -281,8 +237,7 @@ func (t opType) fieldToStringTagField() opType {
"array", "map", "mapLoad", "slice", "struct", "MarshalJSON", "MarshalText", "recursive",
"intString", "uintString",
"intPtr", "uintPtr", "float32Ptr", "float64Ptr", "boolPtr", "stringPtr", "bytesPtr",
"arrayPtr", "slicePtr", "mapPtr", "marshalJSONPtr", "marshalTextPtr",
"intNPtr", "uintNPtr", "float32NPtr", "float64NPtr", "boolNPtr", "stringNPtr", "bytesNPtr",
"arrayPtr", "slicePtr", "mapPtr", "marshalJSONPtr", "marshalTextPtr", "interfacePtr",
}
primitiveTypesUpper := []string{}
for _, typ := range primitiveTypes {
@ -292,16 +247,12 @@ func (t opType) fieldToStringTagField() opType {
createOpType("End", "Op"),
createOpType("Interface", "Op"),
createOpType("Ptr", "Op"),
createOpType("NPtr", "Op"),
createOpType("SliceHead", "SliceHead"),
createOpType("RootSliceHead", "SliceHead"),
createOpType("SliceElem", "SliceElem"),
createOpType("RootSliceElem", "SliceElem"),
createOpType("SliceEnd", "Op"),
createOpType("ArrayHead", "ArrayHead"),
createOpType("ArrayElem", "ArrayElem"),
createOpType("ArrayEnd", "Op"),
createOpType("MapHead", "MapHead"),
createOpType("MapHeadLoad", "MapHead"),
createOpType("MapKey", "MapKey"),
createOpType("MapValue", "MapValue"),
@ -314,77 +265,53 @@ func (t opType) fieldToStringTagField() opType {
opTypes = append(opTypes, createOpType(typ, "Op"))
}
for _, typ := range append(primitiveTypesUpper, "") {
for _, ptrOrNot := range []string{"", "Ptr", "NPtr"} {
for _, headType := range []string{"", "Anonymous"} {
for _, opt := range []string{"", "OmitEmpty", "StringTag"} {
ptrOrNot := ptrOrNot
headType := headType
opt := opt
typ := typ
for _, ptrOrNot := range []string{"", "Ptr"} {
for _, opt := range []string{"", "OmitEmpty", "StringTag"} {
ptrOrNot := ptrOrNot
opt := opt
typ := typ
op := fmt.Sprintf(
"StructField%s%sHead%s%s",
ptrOrNot,
headType,
opt,
typ,
)
opTypes = append(opTypes, opType{
Op: op,
Code: "StructField",
HeadToPtrHead: func() string {
return fmt.Sprintf(
"StructFieldPtr%sHead%s%s",
headType,
opt,
typ,
)
},
HeadToNPtrHead: func() string {
return fmt.Sprintf(
"StructFieldNPtr%sHead%s%s",
headType,
opt,
typ,
)
},
HeadToAnonymousHead: func() string {
return fmt.Sprintf(
"StructField%sAnonymousHead%s%s",
ptrOrNot,
opt,
typ,
)
},
HeadToOmitEmptyHead: func() string {
return fmt.Sprintf(
"StructField%s%sHeadOmitEmpty%s",
ptrOrNot,
headType,
typ,
)
},
HeadToStringTagHead: func() string {
return fmt.Sprintf(
"StructField%s%sHeadStringTag%s",
ptrOrNot,
headType,
typ,
)
},
PtrHeadToHead: func() string {
return fmt.Sprintf(
"StructField%sHead%s%s",
headType,
opt,
typ,
)
},
FieldToEnd: func() string { return op },
FieldToOmitEmptyField: func() string { return op },
FieldToStringTagField: func() string { return op },
})
}
op := fmt.Sprintf(
"StructField%sHead%s%s",
ptrOrNot,
opt,
typ,
)
opTypes = append(opTypes, opType{
Op: op,
Code: "StructField",
HeadToPtrHead: func() string {
return fmt.Sprintf(
"StructFieldPtrHead%s%s",
opt,
typ,
)
},
HeadToOmitEmptyHead: func() string {
return fmt.Sprintf(
"StructField%sHeadOmitEmpty%s",
ptrOrNot,
typ,
)
},
HeadToStringTagHead: func() string {
return fmt.Sprintf(
"StructField%sHeadStringTag%s",
ptrOrNot,
typ,
)
},
PtrHeadToHead: func() string {
return fmt.Sprintf(
"StructFieldHead%s%s",
opt,
typ,
)
},
FieldToEnd: func() string { return op },
FieldToOmitEmptyField: func() string { return op },
FieldToStringTagField: func() string { return op },
})
}
}
}
@ -402,8 +329,6 @@ func (t opType) fieldToStringTagField() opType {
Op: op,
Code: "StructField",
HeadToPtrHead: func() string { return op },
HeadToNPtrHead: func() string { return op },
HeadToAnonymousHead: func() string { return op },
HeadToOmitEmptyHead: func() string { return op },
HeadToStringTagHead: func() string { return op },
PtrHeadToHead: func() string { return op },
@ -447,8 +372,6 @@ func (t opType) fieldToStringTagField() opType {
Op: op,
Code: "StructEnd",
HeadToPtrHead: func() string { return op },
HeadToNPtrHead: func() string { return op },
HeadToAnonymousHead: func() string { return op },
HeadToOmitEmptyHead: func() string { return op },
HeadToStringTagHead: func() string { return op },
PtrHeadToHead: func() string { return op },

View File

@ -96,9 +96,7 @@ func encodeCompileHead(ctx *encodeCompileContext) (*opcode, error) {
func encodeLinkRecursiveCode(c *opcode) {
for code := c; code.op != opEnd && code.op != opStructFieldRecursiveEnd; {
switch code.op {
case opStructFieldRecursive,
opStructFieldPtrAnonymousHeadRecursive,
opStructFieldAnonymousHeadRecursive:
case opStructFieldRecursive, opStructFieldPtrHeadRecursive:
if code.jmp.linked {
code = code.next
continue
@ -253,11 +251,46 @@ func encodeCompile(ctx *encodeCompileContext, isPtr bool) (*opcode, error) {
return nil, &UnsupportedTypeError{Type: rtype2type(typ)}
}
func encodeConvertPtrOp(code *opcode) opType {
ptrHeadOp := code.op.headToPtrHead()
if code.op != ptrHeadOp {
return ptrHeadOp
}
switch code.op {
case opInt:
return opIntPtr
case opUint:
return opUintPtr
case opFloat32:
return opFloat32Ptr
case opFloat64:
return opFloat64Ptr
case opString:
return opStringPtr
case opBool:
return opBoolPtr
case opBytes:
return opBytesPtr
case opArray:
return opArrayPtr
case opSlice:
return opSlicePtr
case opMap:
return opMapPtr
case opMarshalJSON:
return opMarshalJSONPtr
case opMarshalText:
return opMarshalTextPtr
case opInterface:
return opInterfacePtr
}
return code.op
}
func encodeCompileKey(ctx *encodeCompileContext) (*opcode, error) {
typ := ctx.typ
switch {
case rtype_ptrTo(typ).Implements(marshalJSONType):
fmt.Println("key MarshalJSON", typ)
return encodeCompileMarshalJSONPtr(ctx)
case rtype_ptrTo(typ).Implements(marshalTextType):
return encodeCompileMarshalTextPtr(ctx)
@ -296,24 +329,13 @@ func encodeCompileKey(ctx *encodeCompileContext) (*opcode, error) {
}
func encodeCompilePtr(ctx *encodeCompileContext) (*opcode, error) {
ptrOpcodeIndex := ctx.opcodeIndex
ptrIndex := ctx.ptrIndex
ctx.incIndex()
code, err := encodeCompile(ctx.withType(ctx.typ.Elem()), true)
if err != nil {
return nil, err
}
ptrHeadOp := code.op.headToPtrHead()
if code.op != ptrHeadOp {
code.op = ptrHeadOp
code.decOpcodeIndex()
ctx.decIndex()
return code, nil
}
c := ctx.context()
c.opcodeIndex = ptrOpcodeIndex
c.ptrIndex = ptrIndex
return newOpCodeWithNext(c, opPtr, code), nil
code.op = encodeConvertPtrOp(code)
code.ptrNum++
return code, nil
}
func encodeCompileMarshalJSON(ctx *encodeCompileContext) (*opcode, error) {
@ -693,181 +715,102 @@ func encodeCompileMap(ctx *encodeCompileContext, withLoad bool) (*opcode, error)
func encodeTypeToHeaderType(ctx *encodeCompileContext, code *opcode) opType {
switch code.op {
case opPtr:
ptrNum := 1
c := code
ctx.decIndex()
for {
if code.next.op == opPtr {
ptrNum++
code = code.next
ctx.decIndex()
continue
}
break
}
c.ptrNum = ptrNum
if ptrNum > 1 {
switch code.next.op {
case opInt:
c.mask = code.next.mask
c.rshiftNum = code.next.rshiftNum
return opStructFieldHeadIntNPtr
case opUint:
c.mask = code.next.mask
return opStructFieldHeadUintNPtr
case opFloat32:
return opStructFieldHeadFloat32NPtr
case opFloat64:
return opStructFieldHeadFloat64NPtr
case opString:
return opStructFieldHeadStringNPtr
case opBool:
return opStructFieldHeadBoolNPtr
}
} else {
switch code.next.op {
case opInt:
c.mask = code.next.mask
c.rshiftNum = code.next.rshiftNum
return opStructFieldHeadIntPtr
case opUint:
c.mask = code.next.mask
return opStructFieldHeadUintPtr
case opFloat32:
return opStructFieldHeadFloat32Ptr
case opFloat64:
return opStructFieldHeadFloat64Ptr
case opString:
return opStructFieldHeadStringPtr
case opBool:
return opStructFieldHeadBoolPtr
case opSliceHead:
return opStructFieldHeadSlicePtr
case opArrayHead:
return opStructFieldHeadArrayPtr
case opMapHead:
return opStructFieldHeadMapPtr
case opMarshalJSON:
return opStructFieldHeadMarshalJSONPtr
case opMarshalText:
return opStructFieldHeadMarshalTextPtr
}
}
case opInt:
return opStructFieldHeadInt
case opIntPtr:
return opStructFieldHeadIntPtr
case opUint:
return opStructFieldHeadUint
case opUintPtr:
return opStructFieldHeadUintPtr
case opFloat32:
return opStructFieldHeadFloat32
case opFloat32Ptr:
return opStructFieldHeadFloat32Ptr
case opFloat64:
return opStructFieldHeadFloat64
case opFloat64Ptr:
return opStructFieldHeadFloat64Ptr
case opString:
return opStructFieldHeadString
case opStringPtr:
return opStructFieldHeadStringPtr
case opBool:
return opStructFieldHeadBool
case opMapHead:
case opBoolPtr:
return opStructFieldHeadBoolPtr
case opMap:
return opStructFieldHeadMap
case opMapPtr:
code.op = opMap
return opStructFieldHeadMapPtr
case opMapHeadLoad:
return opStructFieldHeadMapLoad
case opArrayHead:
case opArray:
return opStructFieldHeadArray
case opSliceHead:
case opArrayPtr:
code.op = opArray
return opStructFieldHeadArrayPtr
case opSlice:
return opStructFieldHeadSlice
case opSlicePtr:
code.op = opSlice
return opStructFieldHeadSlicePtr
case opMarshalJSON:
return opStructFieldHeadMarshalJSON
case opMarshalJSONPtr:
return opStructFieldHeadMarshalJSONPtr
case opMarshalText:
return opStructFieldHeadMarshalText
case opMarshalTextPtr:
return opStructFieldHeadMarshalTextPtr
}
return opStructFieldHead
}
func encodeTypeToFieldType(ctx *encodeCompileContext, code *opcode) opType {
switch code.op {
case opPtr:
ptrNum := 1
ctx.decIndex()
c := code
for {
if code.next.op == opPtr {
ptrNum++
code = code.next
ctx.decIndex()
continue
}
break
}
c.ptrNum = ptrNum
if ptrNum > 1 {
switch code.next.op {
case opInt:
c.mask = code.next.mask
c.rshiftNum = code.next.rshiftNum
return opStructFieldIntNPtr
case opUint:
c.mask = code.next.mask
return opStructFieldUintNPtr
case opFloat32:
return opStructFieldFloat32NPtr
case opFloat64:
return opStructFieldFloat64NPtr
case opString:
return opStructFieldStringNPtr
case opBool:
return opStructFieldBoolNPtr
}
} else {
switch code.next.op {
case opInt:
c.mask = code.next.mask
c.rshiftNum = code.next.rshiftNum
return opStructFieldIntPtr
case opUint:
c.mask = code.next.mask
return opStructFieldUintPtr
case opFloat32:
return opStructFieldFloat32Ptr
case opFloat64:
return opStructFieldFloat64Ptr
case opString:
return opStructFieldStringPtr
case opBool:
return opStructFieldBoolPtr
case opSliceHead:
return opStructFieldSlicePtr
case opArrayHead:
return opStructFieldArrayPtr
case opMapHead:
return opStructFieldMapPtr
case opMarshalJSON:
return opStructFieldMarshalJSONPtr
case opMarshalText:
return opStructFieldMarshalTextPtr
}
}
case opInt:
return opStructFieldInt
case opIntPtr:
return opStructFieldIntPtr
case opUint:
return opStructFieldUint
case opUintPtr:
return opStructFieldUintPtr
case opFloat32:
return opStructFieldFloat32
case opFloat32Ptr:
return opStructFieldFloat32Ptr
case opFloat64:
return opStructFieldFloat64
case opFloat64Ptr:
return opStructFieldFloat64Ptr
case opString:
return opStructFieldString
case opStringPtr:
return opStructFieldStringPtr
case opBool:
return opStructFieldBool
case opMapHead:
case opBoolPtr:
return opStructFieldBoolPtr
case opMap:
return opStructFieldMap
case opMapPtr:
code.op = opMap
return opStructFieldMapPtr
case opMapHeadLoad:
return opStructFieldMapLoad
case opArrayHead:
case opArray:
return opStructFieldArray
case opSliceHead:
case opArrayPtr:
code.op = opArray
return opStructFieldArrayPtr
case opSlice:
return opStructFieldSlice
case opSlicePtr:
code.op = opSlice
return opStructFieldSlicePtr
case opStructFieldHead:
return opStructFieldStruct
case opMarshalJSON:
@ -876,6 +819,8 @@ func encodeTypeToFieldType(ctx *encodeCompileContext, code *opcode) opType {
return opStructFieldMarshalJSONPtr
case opMarshalText:
return opStructFieldMarshalText
case opMarshalTextPtr:
return opStructFieldMarshalTextPtr
}
return opStructField
}
@ -952,7 +897,6 @@ func encodeStructHeader(ctx *encodeCompileContext, fieldCode *opcode, valueCode
opStructFieldHeadMapPtr,
opStructFieldHeadOmitEmptyMapPtr,
opStructFieldHeadStringTagMapPtr:
*valueCode = *valueCode.next
return valueCode.beforeLastCode()
case opStructFieldHeadMarshalJSONPtr,
opStructFieldHeadOmitEmptyMarshalJSONPtr,
@ -961,7 +905,6 @@ func encodeStructHeader(ctx *encodeCompileContext, fieldCode *opcode, valueCode
opStructFieldHeadOmitEmptyMarshalTextPtr,
opStructFieldHeadStringTagMarshalTextPtr:
ctx.decOpcodeIndex()
fieldCode.typ = fieldCode.typ.Elem()
return (*opcode)(unsafe.Pointer(fieldCode))
}
ctx.decOpcodeIndex()
@ -1003,7 +946,6 @@ func encodeStructField(ctx *encodeCompileContext, fieldCode *opcode, valueCode *
opStructFieldMapPtr,
opStructFieldOmitEmptyMapPtr,
opStructFieldStringTagMapPtr:
*valueCode = *valueCode.next
return valueCode.beforeLastCode()
}
ctx.decIndex()
@ -1014,9 +956,6 @@ func encodeIsNotExistsField(head *opcode) bool {
if head == nil {
return false
}
if head.op != opStructFieldAnonymousHead {
return false
}
if head.next == nil {
return false
}
@ -1076,15 +1015,8 @@ func encodeAnonymousStructFieldPairMap(tags structTags, named string, valueCode
removedFields := map[*opcode]struct{}{}
for {
existsKey := tags.existsKey(f.displayKey)
op := f.op.headToAnonymousHead()
if existsKey && (f.next.op == opStructFieldPtrAnonymousHeadRecursive || f.next.op == opStructFieldAnonymousHeadRecursive) {
if existsKey && (f.next.op == opStructFieldPtrHeadRecursive || f.next.op == opStructFieldHeadRecursive) {
// through
} else if op != f.op {
if existsKey {
f.op = opStructFieldAnonymousHead
} else if named == "" {
//f.op = op
}
} else if named == "" && f.op == opStructEnd {
f.op = opStructAnonymousEnd
} else if existsKey {
@ -1166,7 +1098,7 @@ func encodeOptimizeConflictAnonymousFields(anonymousFields map[string][]structFi
if !fieldPair.linked {
if fieldPair.prevField == nil {
// head operation
fieldPair.curField.op = opStructFieldAnonymousHead
fieldPair.curField.op = opStructFieldHead
} else {
diff := fieldPair.curField.nextField.displayIdx - fieldPair.curField.displayIdx
for i := 0; i < diff; i++ {
@ -1184,7 +1116,7 @@ func encodeOptimizeConflictAnonymousFields(anonymousFields map[string][]structFi
if !fieldPair.linked {
if fieldPair.prevField == nil {
// head operation
fieldPair.curField.op = opStructFieldAnonymousHead
fieldPair.curField.op = opStructFieldHead
} else {
diff := fieldPair.curField.nextField.displayIdx - fieldPair.curField.displayIdx
removedFields[fieldPair.curField] = struct{}{}

View File

@ -378,7 +378,7 @@ func newSliceHeaderCode(ctx *encodeCompileContext) *opcode {
ctx.incPtrIndex()
length := opcodeOffset(ctx.ptrIndex)
return &opcode{
op: opSliceHead,
op: opSlice,
displayIdx: ctx.opcodeIndex,
idx: idx,
headIdx: idx,
@ -406,7 +406,7 @@ func newArrayHeaderCode(ctx *encodeCompileContext, alen int) *opcode {
ctx.incPtrIndex()
elemIdx := opcodeOffset(ctx.ptrIndex)
return &opcode{
op: opArrayHead,
op: opArray,
displayIdx: ctx.opcodeIndex,
idx: idx,
headIdx: idx,
@ -434,7 +434,7 @@ func newMapHeaderCode(ctx *encodeCompileContext, withLoad bool) *opcode {
if withLoad {
op = opMapHeadLoad
} else {
op = opMapHead
op = opMap
}
idx := opcodeOffset(ctx.ptrIndex)
ctx.incPtrIndex()

File diff suppressed because it is too large Load Diff

View File

@ -237,7 +237,7 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
b = encodeComma(b)
}
code = code.next
case opSliceHead:
case opSlice:
p := load(ctxptr, code.idx)
slice := ptrToSlice(p)
if p == 0 || slice.data == nil {
@ -273,7 +273,7 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
b = encodeComma(b)
code = code.end.next
}
case opArrayHead:
case opArray:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
@ -305,7 +305,7 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
b = encodeComma(b)
code = code.end.next
}
case opMapHead:
case opMap:
ptr := load(ctxptr, code.idx)
if ptr == 0 {
b = encodeNull(b)
@ -772,29 +772,6 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
}
b = encodeComma(b)
code = code.next
case opStructFieldHeadIntNPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
if !code.anonymousHead {
b = append(b, '{')
}
b = append(b, code.key...)
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = appendInt(b, ptrToUint64(p), code)
}
}
b = encodeComma(b)
code = code.next
case opStructFieldPtrHeadUint:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
@ -977,29 +954,6 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
}
b = encodeComma(b)
code = code.next
case opStructFieldHeadUintNPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
if !code.anonymousHead {
b = append(b, '{')
}
b = append(b, code.key...)
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = appendUint(b, ptrToUint64(p), code)
}
}
b = encodeComma(b)
code = code.next
case opStructFieldPtrHeadFloat32:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
@ -1181,29 +1135,6 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
}
b = encodeComma(b)
code = code.next
case opStructFieldHeadFloat32NPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
if !code.anonymousHead {
b = append(b, '{')
}
b = append(b, code.key...)
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = encodeFloat32(b, ptrToFloat32(p+code.offset))
}
}
b = encodeComma(b)
code = code.next
case opStructFieldPtrHeadFloat64:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
@ -1408,33 +1339,6 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
}
b = encodeComma(b)
code = code.next
case opStructFieldHeadFloat64NPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
if !code.anonymousHead {
b = append(b, '{')
}
b = append(b, code.key...)
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
v := ptrToFloat64(p)
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
}
b = encodeFloat64(b, v)
}
}
b = encodeComma(b)
code = code.next
case opStructFieldPtrHeadString:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
@ -1613,29 +1517,6 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
}
b = encodeComma(b)
code = code.next
case opStructFieldHeadStringNPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
if !code.anonymousHead {
b = append(b, '{')
}
b = append(b, code.key...)
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = encodeNoEscapedString(b, ptrToString(p+code.offset))
}
}
b = encodeComma(b)
code = code.next
case opStructFieldPtrHeadBool:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
@ -1817,29 +1698,6 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
}
b = encodeComma(b)
code = code.next
case opStructFieldHeadBoolNPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
if !code.anonymousHead {
b = append(b, '{')
}
b = append(b, code.key...)
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = encodeBool(b, ptrToBool(p+code.offset))
}
}
b = encodeComma(b)
code = code.next
case opStructFieldPtrHeadBytes:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
@ -2822,23 +2680,6 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
}
b = encodeComma(b)
code = code.next
case opStructFieldIntNPtr:
b = append(b, code.key...)
ptr := load(ctxptr, code.headIdx)
p := ptrToPtr(ptr + code.offset)
for i := 0; i < code.ptrNum-1; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = appendInt(b, ptrToUint64(p), code)
}
b = encodeComma(b)
code = code.next
case opStructFieldUint:
ptr := load(ctxptr, code.headIdx)
b = append(b, code.key...)
@ -3529,23 +3370,6 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
}
b = appendStructEnd(b)
code = code.next
case opStructEndIntNPtr:
b = append(b, code.key...)
ptr := load(ctxptr, code.headIdx)
p := ptrToPtr(ptr + code.offset)
for i := 0; i < code.ptrNum-1; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = appendInt(b, ptrToUint64(p), code)
}
b = appendStructEnd(b)
code = code.next
case opStructEndUint:
ptr := load(ctxptr, code.headIdx)
b = append(b, code.key...)
@ -3619,23 +3443,6 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
}
b = appendStructEnd(b)
code = code.next
case opStructEndUintNPtr:
b = append(b, code.key...)
ptr := load(ctxptr, code.headIdx)
p := ptrToPtr(ptr + code.offset)
for i := 0; i < code.ptrNum-1; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = appendUint(b, ptrToUint64(p), code)
}
b = appendStructEnd(b)
code = code.next
case opStructEndFloat32:
ptr := load(ctxptr, code.headIdx)
b = append(b, code.key...)
@ -3708,23 +3515,6 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
}
b = appendStructEnd(b)
code = code.next
case opStructEndFloat32NPtr:
b = append(b, code.key...)
ptr := load(ctxptr, code.headIdx)
p := ptrToPtr(ptr + code.offset)
for i := 0; i < code.ptrNum-1; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = encodeFloat32(b, ptrToFloat32(p))
}
b = appendStructEnd(b)
code = code.next
case opStructEndFloat64:
ptr := load(ctxptr, code.headIdx)
b = append(b, code.key...)
@ -3822,27 +3612,6 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
}
b = appendStructEnd(b)
code = code.next
case opStructEndFloat64NPtr:
b = append(b, code.key...)
ptr := load(ctxptr, code.headIdx)
p := ptrToPtr(ptr + code.offset)
for i := 0; i < code.ptrNum-1; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
v := ptrToFloat64(p)
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
}
b = encodeFloat64(b, v)
}
b = appendStructEnd(b)
code = code.next
case opStructEndString:
ptr := load(ctxptr, code.headIdx)
b = append(b, code.key...)
@ -3913,23 +3682,6 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco
}
b = appendStructEnd(b)
code = code.next
case opStructEndStringNPtr:
b = append(b, code.key...)
ptr := load(ctxptr, code.headIdx)
p := ptrToPtr(ptr + code.offset)
for i := 0; i < code.ptrNum-1; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = encodeNoEscapedString(b, ptrToString(p))
}
b = appendStructEnd(b)
code = code.next
case opStructEndBool:
ptr := load(ctxptr, code.headIdx)
b = append(b, code.key...)

View File

@ -77,6 +77,16 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
}
b = encodeComma(b)
code = code.next
case opInterfacePtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeComma(b)
code = code.next
break
}
store(ctxptr, code.idx, ptrToPtr(p))
fallthrough
case opInterface:
ptr := load(ctxptr, code.idx)
if ptr == 0 {
@ -179,7 +189,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
b = encodeComma(b)
}
code = code.next
case opSliceHead:
case opSlice:
p := load(ctxptr, code.idx)
slice := ptrToSlice(p)
if p == 0 || uintptr(slice.data) == 0 {
@ -215,7 +225,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
b = encodeComma(b)
code = code.end.next
}
case opArrayHead:
case opArray:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
@ -247,7 +257,7 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
b = encodeComma(b)
code = code.end.next
}
case opMapHead:
case opMap:
ptr := load(ctxptr, code.idx)
if ptr == 0 {
b = encodeNull(b)
@ -534,7 +544,14 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
store(ctxptr, code.idx, p)
case opStructFieldPtrHeadInt:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
p := load(ctxptr, code.idx)
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
store(ctxptr, code.idx, p)
}
fallthrough
case opStructFieldHeadInt:
@ -714,29 +731,6 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
}
b = encodeComma(b)
code = code.next
case opStructFieldHeadIntNPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
if !code.anonymousHead {
b = append(b, '{')
}
b = append(b, code.escapedKey...)
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = appendInt(b, ptrToUint64(p), code)
}
}
b = encodeComma(b)
code = code.next
case opStructFieldPtrHeadUint:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
@ -919,29 +913,6 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
}
b = encodeComma(b)
code = code.next
case opStructFieldHeadUintNPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
if !code.anonymousHead {
b = append(b, '{')
}
b = append(b, code.escapedKey...)
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = appendUint(b, ptrToUint64(p), code)
}
}
b = encodeComma(b)
code = code.next
case opStructFieldPtrHeadFloat32:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
@ -1123,29 +1094,6 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
}
b = encodeComma(b)
code = code.next
case opStructFieldHeadFloat32NPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
if !code.anonymousHead {
b = append(b, '{')
}
b = append(b, code.escapedKey...)
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = encodeFloat32(b, ptrToFloat32(p+code.offset))
}
}
b = encodeComma(b)
code = code.next
case opStructFieldPtrHeadFloat64:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
@ -1350,36 +1298,16 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
}
b = encodeComma(b)
code = code.next
case opStructFieldHeadFloat64NPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
if !code.anonymousHead {
b = append(b, '{')
}
b = append(b, code.escapedKey...)
case opStructFieldPtrHeadString:
if code.indirect {
p := load(ctxptr, code.idx)
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
v := ptrToFloat64(p)
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
}
b = encodeFloat64(b, v)
}
}
b = encodeComma(b)
code = code.next
case opStructFieldPtrHeadString:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
store(ctxptr, code.idx, p)
}
fallthrough
case opStructFieldHeadString:
@ -1555,29 +1483,6 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
}
b = encodeComma(b)
code = code.next
case opStructFieldHeadStringNPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
if !code.anonymousHead {
b = append(b, '{')
}
b = append(b, code.escapedKey...)
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = encodeEscapedString(b, ptrToString(p+code.offset))
}
}
b = encodeComma(b)
code = code.next
case opStructFieldPtrHeadBool:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
@ -1759,29 +1664,6 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
}
b = encodeComma(b)
code = code.next
case opStructFieldHeadBoolNPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
if !code.anonymousHead {
b = append(b, '{')
}
b = append(b, code.escapedKey...)
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = encodeBool(b, ptrToBool(p+code.offset))
}
}
b = encodeComma(b)
code = code.next
case opStructFieldPtrHeadBytes:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
@ -2764,23 +2646,6 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
}
b = encodeComma(b)
code = code.next
case opStructFieldIntNPtr:
b = append(b, code.escapedKey...)
ptr := load(ctxptr, code.headIdx)
p := ptrToPtr(ptr + code.offset)
for i := 0; i < code.ptrNum-1; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = appendInt(b, ptrToUint64(p), code)
}
b = encodeComma(b)
code = code.next
case opStructFieldUint:
ptr := load(ctxptr, code.headIdx)
b = append(b, code.escapedKey...)
@ -3471,23 +3336,6 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
}
b = appendStructEnd(b)
code = code.next
case opStructEndIntNPtr:
b = append(b, code.escapedKey...)
ptr := load(ctxptr, code.headIdx)
p := ptrToPtr(ptr + code.offset)
for i := 0; i < code.ptrNum-1; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = appendInt(b, ptrToUint64(p), code)
}
b = appendStructEnd(b)
code = code.next
case opStructEndUint:
ptr := load(ctxptr, code.headIdx)
b = append(b, code.escapedKey...)
@ -3561,23 +3409,6 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
}
b = appendStructEnd(b)
code = code.next
case opStructEndUintNPtr:
b = append(b, code.escapedKey...)
ptr := load(ctxptr, code.headIdx)
p := ptrToPtr(ptr + code.offset)
for i := 0; i < code.ptrNum-1; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = appendUint(b, ptrToUint64(p), code)
}
b = appendStructEnd(b)
code = code.next
case opStructEndFloat32:
ptr := load(ctxptr, code.headIdx)
b = append(b, code.escapedKey...)
@ -3650,23 +3481,6 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
}
b = appendStructEnd(b)
code = code.next
case opStructEndFloat32NPtr:
b = append(b, code.escapedKey...)
ptr := load(ctxptr, code.headIdx)
p := ptrToPtr(ptr + code.offset)
for i := 0; i < code.ptrNum-1; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = encodeFloat32(b, ptrToFloat32(p))
}
b = appendStructEnd(b)
code = code.next
case opStructEndFloat64:
ptr := load(ctxptr, code.headIdx)
b = append(b, code.escapedKey...)
@ -3764,27 +3578,6 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
}
b = appendStructEnd(b)
code = code.next
case opStructEndFloat64NPtr:
b = append(b, code.escapedKey...)
ptr := load(ctxptr, code.headIdx)
p := ptrToPtr(ptr + code.offset)
for i := 0; i < code.ptrNum-1; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
v := ptrToFloat64(p)
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
}
b = encodeFloat64(b, v)
}
b = appendStructEnd(b)
code = code.next
case opStructEndString:
ptr := load(ctxptr, code.headIdx)
b = append(b, code.escapedKey...)
@ -3855,23 +3648,6 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o
}
b = appendStructEnd(b)
code = code.next
case opStructEndStringNPtr:
b = append(b, code.escapedKey...)
ptr := load(ctxptr, code.headIdx)
p := ptrToPtr(ptr + code.offset)
for i := 0; i < code.ptrNum-1; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = encodeEscapedString(b, ptrToString(p))
}
b = appendStructEnd(b)
code = code.next
case opStructEndBool:
ptr := load(ctxptr, code.headIdx)
b = append(b, code.escapedKey...)

View File

@ -195,7 +195,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
b = encodeIndentComma(b)
}
code = code.next
case opSliceHead:
case opSlice:
p := load(ctxptr, code.idx)
slice := ptrToSlice(p)
if p == 0 || slice.data == nil {
@ -273,7 +273,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
b = append(b, ']')
code = code.end.next
}
case opArrayHead:
case opArray:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
@ -309,7 +309,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
b = append(b, ']', ',', '\n')
code = code.end.next
}
case opMapHead:
case opMap:
ptr := load(ctxptr, code.idx)
if ptr == 0 {
b = encodeNull(b)
@ -812,31 +812,6 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldHeadIntNPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
if !code.anonymousHead {
b = append(b, '{', '\n')
}
b = appendIndent(ctx, b, code.indent+1)
b = append(b, code.escapedKey...)
b = append(b, ' ')
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = appendInt(b, ptrToUint64(p), code)
}
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldPtrHeadUint:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
@ -1030,31 +1005,6 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldHeadUintNPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
if !code.anonymousHead {
b = append(b, '{', '\n')
}
b = appendIndent(ctx, b, code.indent+1)
b = append(b, code.escapedKey...)
b = append(b, ' ')
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = appendUint(b, ptrToUint64(p), code)
}
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldPtrHeadFloat32:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
@ -1247,31 +1197,6 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldHeadFloat32NPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
if !code.anonymousHead {
b = append(b, '{', '\n')
}
b = appendIndent(ctx, b, code.indent+1)
b = append(b, code.escapedKey...)
b = append(b, ' ')
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = encodeFloat32(b, ptrToFloat32(p))
}
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldPtrHeadFloat64:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
@ -1487,35 +1412,6 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldHeadFloat64NPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
if !code.anonymousHead {
b = append(b, '{', '\n')
}
b = appendIndent(ctx, b, code.indent+1)
b = append(b, code.escapedKey...)
b = append(b, ' ')
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
v := ptrToFloat64(p)
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
}
b = encodeFloat64(b, v)
}
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldPtrHeadString:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
@ -1706,31 +1602,6 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldHeadStringNPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
if !code.anonymousHead {
b = append(b, '{', '\n')
}
b = appendIndent(ctx, b, code.indent+1)
b = append(b, code.escapedKey...)
b = append(b, ' ')
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = encodeEscapedString(b, ptrToString(p+code.offset))
}
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldPtrHeadBool:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
@ -1923,31 +1794,6 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldHeadBoolNPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
if !code.anonymousHead {
b = append(b, '{', '\n')
}
b = appendIndent(ctx, b, code.indent+1)
b = append(b, code.escapedKey...)
b = append(b, ' ')
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = encodeBool(b, ptrToBool(p+code.offset))
}
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldPtrHeadBytes:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))

View File

@ -195,7 +195,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
b = encodeIndentComma(b)
}
code = code.next
case opSliceHead:
case opSlice:
p := load(ctxptr, code.idx)
slice := ptrToSlice(p)
if p == 0 || slice.data == nil {
@ -273,7 +273,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
b = append(b, ']')
code = code.end.next
}
case opArrayHead:
case opArray:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
@ -309,7 +309,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
b = append(b, ']', ',', '\n')
code = code.end.next
}
case opMapHead:
case opMap:
ptr := load(ctxptr, code.idx)
if ptr == 0 {
b = encodeNull(b)
@ -812,33 +812,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldHeadIntNPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeIndentComma(b)
code = code.next
break
}
if !code.anonymousHead {
b = append(b, '{', '\n')
}
b = appendIndent(ctx, b, code.indent+1)
b = append(b, code.key...)
b = append(b, ' ')
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = appendInt(b, ptrToUint64(p), code)
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldPtrHeadUint:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
@ -1032,33 +1006,6 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldHeadUintNPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeIndentComma(b)
code = code.next
break
}
if !code.anonymousHead {
b = append(b, '{', '\n')
}
b = appendIndent(ctx, b, code.indent+1)
b = append(b, code.key...)
b = append(b, ' ')
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = appendUint(b, ptrToUint64(p), code)
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldPtrHeadFloat32:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
@ -1251,33 +1198,6 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldHeadFloat32NPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
b = encodeIndentComma(b)
code = code.next
break
}
if !code.anonymousHead {
b = append(b, '{', '\n')
}
b = appendIndent(ctx, b, code.indent+1)
b = append(b, code.key...)
b = append(b, ' ')
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = encodeFloat32(b, ptrToFloat32(p))
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldPtrHeadFloat64:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
@ -1493,35 +1413,6 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldHeadFloat64NPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
if !code.anonymousHead {
b = append(b, '{', '\n')
}
b = appendIndent(ctx, b, code.indent+1)
b = append(b, code.key...)
b = append(b, ' ')
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
v := ptrToFloat64(p)
if math.IsInf(v, 0) || math.IsNaN(v) {
return nil, errUnsupportedFloat(v)
}
b = encodeFloat64(b, v)
}
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldPtrHeadString:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
@ -1712,31 +1603,6 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldHeadStringNPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
if !code.anonymousHead {
b = append(b, '{', '\n')
}
b = appendIndent(ctx, b, code.indent+1)
b = append(b, code.key...)
b = append(b, ' ')
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = encodeNoEscapedString(b, ptrToString(p+code.offset))
}
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldPtrHeadBool:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))
@ -1929,31 +1795,6 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldHeadBoolNPtr:
p := load(ctxptr, code.idx)
if p == 0 {
b = encodeNull(b)
} else {
if !code.anonymousHead {
b = append(b, '{', '\n')
}
b = appendIndent(ctx, b, code.indent+1)
b = append(b, code.key...)
b = append(b, ' ')
for i := 0; i < code.ptrNum; i++ {
if p == 0 {
break
}
p = ptrToPtr(p)
}
if p == 0 {
b = encodeNull(b)
} else {
b = encodeBool(b, ptrToBool(p+code.offset))
}
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldPtrHeadBytes:
if code.indirect {
store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx)))