diff --git a/docker-compose.yml b/docker-compose.yml index 61c7d74..e510666 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,7 @@ services: deploy: resources: limits: - memory: 700M + memory: 620M working_dir: /go/src/go-json command: | sh -c "go test -c . && ls go-json.test" diff --git a/internal/encoder/compiler.go b/internal/encoder/compiler.go index 896123d..128ec48 100644 --- a/internal/encoder/compiler.go +++ b/internal/encoder/compiler.go @@ -1050,7 +1050,6 @@ func compiledCode(ctx *compileContext) *Opcode { } func structHeader(ctx *compileContext, fieldCode *Opcode, valueCode *Opcode, tag *runtime.StructTag) *Opcode { - fieldCode.Indent-- op := optimizeStructHeader(valueCode, tag) fieldCode.Op = op fieldCode.Mask = valueCode.Mask diff --git a/internal/encoder/vm/util.go b/internal/encoder/vm/util.go index 713655e..f8c9c07 100644 --- a/internal/encoder/vm/util.go +++ b/internal/encoder/vm/util.go @@ -76,6 +76,14 @@ func appendComma(b []byte) []byte { return append(b, ',') } +func appendStructKey(_ *encoder.RuntimeContext, code *encoder.Opcode, b []byte) []byte { + return append(b, code.Key...) +} + +func appendStructHead(b []byte) []byte { + return append(b, '{') +} + func appendStructEnd(b []byte) []byte { return append(b, '}', ',') } diff --git a/internal/encoder/vm/vm.go b/internal/encoder/vm/vm.go index 807482c..0214598 100644 --- a/internal/encoder/vm/vm.go +++ b/internal/encoder/vm/vm.go @@ -587,10 +587,10 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if !code.AnonymousKey { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) } p += code.Offset code = code.Next @@ -618,13 +618,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } p += code.Offset if p == 0 || (ptrToPtr(p) == 0 && code.IsNextOpPtrType) { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -653,9 +653,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p+code.Offset), code) b = appendComma(b) code = code.Next @@ -684,14 +684,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendInt(b, u64, code) b = appendComma(b) code = code.Next @@ -721,9 +721,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') @@ -754,14 +754,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, u64, code) b = append(b, '"') @@ -791,9 +791,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -827,13 +827,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p), code) b = appendComma(b) } @@ -861,9 +861,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -899,13 +899,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, ptrToUint64(p), code) b = append(b, '"') @@ -937,9 +937,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p+code.Offset), code) b = appendComma(b) code = code.Next @@ -968,14 +968,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendUint(b, u64, code) b = appendComma(b) code = code.Next @@ -1005,9 +1005,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') @@ -1038,14 +1038,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, u64, code) b = append(b, '"') @@ -1075,9 +1075,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1111,13 +1111,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p), code) b = appendComma(b) } @@ -1145,9 +1145,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1183,13 +1183,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, ptrToUint64(p), code) b = append(b, '"') @@ -1221,9 +1221,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = appendComma(b) code = code.Next @@ -1252,13 +1252,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToFloat32(p + code.Offset) if v == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, v) b = appendComma(b) code = code.Next @@ -1288,9 +1288,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = append(b, '"') @@ -1321,13 +1321,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToFloat32(p + code.Offset) if v == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, v) b = append(b, '"') @@ -1357,9 +1357,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1393,13 +1393,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p)) b = appendComma(b) } @@ -1427,9 +1427,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1465,13 +1465,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p)) b = append(b, '"') @@ -1507,9 +1507,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt return nil, errUnsupportedFloat(v) } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat64(b, v) b = appendComma(b) code = code.Next @@ -1538,7 +1538,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToFloat64(p + code.Offset) if v == 0 { @@ -1547,7 +1547,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat64(b, v) b = appendComma(b) code = code.Next @@ -1577,13 +1577,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToFloat64(p + code.Offset) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') @@ -1614,7 +1614,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToFloat64(p + code.Offset) if v == 0 { @@ -1623,7 +1623,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') @@ -1653,9 +1653,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1693,13 +1693,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -1731,9 +1731,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1773,13 +1773,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { @@ -1815,9 +1815,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p+code.Offset)) b = appendComma(b) code = code.Next @@ -1846,13 +1846,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToString(p + code.Offset) if v == "" { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, v) b = appendComma(b) code = code.Next @@ -1882,9 +1882,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) s := ptrToString(p + code.Offset) b = appendString(b, string(appendString([]byte{}, s))) b = appendComma(b) @@ -1914,13 +1914,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToString(p + code.Offset) if v == "" { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, v))) b = appendComma(b) code = code.Next @@ -1948,9 +1948,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1984,13 +1984,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p)) b = appendComma(b) } @@ -2018,9 +2018,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2054,13 +2054,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, ptrToString(p)))) b = appendComma(b) } @@ -2090,9 +2090,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p+code.Offset)) b = appendComma(b) code = code.Next @@ -2121,11 +2121,11 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToBool(p + code.Offset) if v { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendBool(b, v) b = appendComma(b) code = code.Next @@ -2157,9 +2157,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, ptrToBool(p+code.Offset)) b = append(b, '"') @@ -2190,11 +2190,11 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToBool(p + code.Offset) if v { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, v) b = append(b, '"') @@ -2226,9 +2226,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2262,13 +2262,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p)) b = appendComma(b) } @@ -2296,9 +2296,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2334,13 +2334,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, ptrToBool(p)) b = append(b, '"') @@ -2372,9 +2372,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p+code.Offset)) b = appendComma(b) code = code.Next @@ -2403,13 +2403,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToBytes(p + code.Offset) if v == nil { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p)) b = appendComma(b) code = code.Next @@ -2437,9 +2437,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2473,13 +2473,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p)) b = appendComma(b) } @@ -2509,9 +2509,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { return nil, err @@ -2543,13 +2543,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToNumber(p + code.Offset) if v == "" { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, v) if err != nil { return nil, err @@ -2582,9 +2582,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { @@ -2618,13 +2618,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToNumber(p + code.Offset) if v == "" { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, v) if err != nil { @@ -2657,9 +2657,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2697,13 +2697,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { return nil, err @@ -2734,9 +2734,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2775,13 +2775,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { @@ -2816,9 +2816,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p += code.Offset code = code.Next store(ctxptr, code.Idx, p) @@ -2847,10 +2847,10 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } p += code.Offset - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) case encoder.OpStructPtrHeadOmitEmptySlice: @@ -2878,14 +2878,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } p += code.Offset slice := ptrToSlice(p) if slice.Len == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -2912,9 +2912,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2949,7 +2949,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) @@ -2957,7 +2957,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -2984,9 +2984,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if p != 0 && code.Indirect { p = ptrToPtr(p + code.Offset) } @@ -3015,7 +3015,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if p != 0 && code.Indirect { p = ptrToPtr(p + code.Offset) @@ -3023,7 +3023,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if maplen(ptrToUnsafePtr(p)) == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -3050,9 +3050,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) b = appendComma(b) @@ -3094,7 +3094,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if p == 0 { code = code.NextField @@ -3107,7 +3107,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if code.Indirect { p = ptrToNPtr(p, code.PtrNum) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -3136,9 +3136,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.IsNilableType { if code.Indirect || code.Op == encoder.OpStructPtrHeadMarshalJSON { p = ptrToPtr(p + code.Offset) @@ -3180,7 +3180,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.IsNilableType { if code.Indirect || code.Op == encoder.OpStructPtrHeadOmitEmptyMarshalJSON { @@ -3191,7 +3191,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if code.Nilcheck && encoder.IsNilForMarshaler(iface) { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalJSON(ctx, code, b, iface, false) if err != nil { return nil, err @@ -3223,9 +3223,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -3266,12 +3266,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p = ptrToNPtr(p+code.Offset, code.PtrNum) } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if p == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), false) if err != nil { return nil, err @@ -3305,9 +3305,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.IsNilableType { if code.Indirect || code.Op == encoder.OpStructPtrHeadMarshalText { p = ptrToPtr(p + code.Offset) @@ -3349,7 +3349,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.IsNilableType { if code.Indirect || code.Op == encoder.OpStructPtrHeadOmitEmptyMarshalText { @@ -3359,7 +3359,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 && code.Nilcheck { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalText(code, b, ptrToInterface(code, p), false) if err != nil { return nil, err @@ -3391,9 +3391,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -3434,12 +3434,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p = ptrToNPtr(p+code.Offset, code.PtrNum) } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if p == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalText(code, b, ptrToInterface(code, p), false) if err != nil { return nil, err @@ -3450,7 +3450,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } case encoder.OpStructField: if !code.AnonymousKey { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) } p := load(ctxptr, code.HeadIdx) + code.Offset code = code.Next @@ -3461,13 +3461,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if ptrToPtr(p) == 0 && code.IsNextOpPtrType { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } case encoder.OpStructFieldInt: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p+code.Offset), code) b = appendComma(b) code = code.Next @@ -3476,14 +3476,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendInt(b, u64, code) b = appendComma(b) } code = code.Next case encoder.OpStructFieldIntString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') @@ -3494,7 +3494,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, u64, code) b = append(b, '"') @@ -3502,7 +3502,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldIntPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3516,7 +3516,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p), code) b = appendComma(b) } @@ -3524,7 +3524,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldIntPtrString: p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3538,7 +3538,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, ptrToUint64(p), code) b = append(b, '"') @@ -3547,7 +3547,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldUint: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p+code.Offset), code) b = appendComma(b) code = code.Next @@ -3556,14 +3556,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendUint(b, u64, code) b = appendComma(b) } code = code.Next case encoder.OpStructFieldUintString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') @@ -3574,7 +3574,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, u64, code) b = append(b, '"') @@ -3582,7 +3582,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldUintPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3596,7 +3596,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p), code) b = appendComma(b) } @@ -3604,7 +3604,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldUintPtrString: p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3618,7 +3618,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, ptrToUint64(p), code) b = append(b, '"') @@ -3627,7 +3627,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldFloat32: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = appendComma(b) code = code.Next @@ -3635,14 +3635,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat32(p + code.Offset) if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, v) b = appendComma(b) } code = code.Next case encoder.OpStructFieldFloat32String: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = append(b, '"') @@ -3652,7 +3652,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat32(p + code.Offset) if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, v) b = append(b, '"') @@ -3660,7 +3660,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldFloat32Ptr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3674,7 +3674,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p)) b = appendComma(b) } @@ -3682,7 +3682,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldFloat32PtrString: p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3696,7 +3696,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p)) b = append(b, '"') @@ -3705,7 +3705,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldFloat64: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p + code.Offset) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -3720,7 +3720,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat64(b, v) b = appendComma(b) } @@ -3731,7 +3731,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') @@ -3744,7 +3744,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') @@ -3752,7 +3752,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldFloat64Ptr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3772,7 +3772,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -3784,7 +3784,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldFloat64PtrString: p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3802,7 +3802,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { @@ -3815,7 +3815,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p+code.Offset)) b = appendComma(b) code = code.Next @@ -3823,14 +3823,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToString(p + code.Offset) if v != "" { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, v) b = appendComma(b) } code = code.Next case encoder.OpStructFieldStringString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) s := ptrToString(p + code.Offset) b = appendString(b, string(appendString([]byte{}, s))) b = appendComma(b) @@ -3839,13 +3839,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToString(p + code.Offset) if v != "" { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, v))) b = appendComma(b) } code = code.Next case encoder.OpStructFieldStringPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3859,13 +3859,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p)) b = appendComma(b) } code = code.Next case encoder.OpStructFieldStringPtrString: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3879,14 +3879,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, ptrToString(p)))) b = appendComma(b) } code = code.Next case encoder.OpStructFieldBool: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p+code.Offset)) b = appendComma(b) code = code.Next @@ -3894,14 +3894,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBool(p + code.Offset) if v { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendBool(b, v) b = appendComma(b) } code = code.Next case encoder.OpStructFieldBoolString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, ptrToBool(p+code.Offset)) b = append(b, '"') @@ -3911,7 +3911,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBool(p + code.Offset) if v { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, v) b = append(b, '"') @@ -3919,7 +3919,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldBoolPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3933,13 +3933,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p)) b = appendComma(b) } code = code.Next case encoder.OpStructFieldBoolPtrString: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3955,7 +3955,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, ptrToBool(p)) b = append(b, '"') @@ -3964,7 +3964,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldBytes: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p+code.Offset)) b = appendComma(b) code = code.Next @@ -3972,13 +3972,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBytes(p + code.Offset) if len(v) > 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, v) b = appendComma(b) } code = code.Next case encoder.OpStructFieldBytesPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3992,14 +3992,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p)) b = appendComma(b) } code = code.Next case encoder.OpStructFieldNumber: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { return nil, err @@ -4010,7 +4010,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToNumber(p + code.Offset) if v != "" { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, v) if err != nil { return nil, err @@ -4020,7 +4020,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldNumberString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { @@ -4033,7 +4033,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToNumber(p + code.Offset) if v != "" { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, v) if err != nil { @@ -4044,7 +4044,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldNumberPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4062,7 +4062,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { return nil, err @@ -4071,7 +4071,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldNumberPtrString: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4090,7 +4090,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { @@ -4102,7 +4102,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldMarshalJSON: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p += code.Offset if code.IsNilableType { p = ptrToPtr(p) @@ -4133,7 +4133,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.NextField break } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalJSON(ctx, code, b, iface, false) if err != nil { return nil, err @@ -4142,7 +4142,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldMarshalJSONPtr: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { b = appendNull(b) @@ -4159,7 +4159,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), false) if err != nil { return nil, err @@ -4169,7 +4169,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldMarshalText: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p += code.Offset if code.IsNilableType { p = ptrToPtr(p) @@ -4195,7 +4195,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.NextField break } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalText(code, b, ptrToInterface(code, p), false) if err != nil { return nil, err @@ -4204,7 +4204,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldMarshalTextPtr: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { b = appendNull(b) @@ -4221,7 +4221,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalText(code, b, ptrToInterface(code, p), false) if err != nil { return nil, err @@ -4230,7 +4230,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldArray: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p += code.Offset code = code.Next @@ -4238,11 +4238,11 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldOmitEmptyArray: p := load(ctxptr, code.HeadIdx) p += code.Offset - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) case encoder.OpStructFieldArrayPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) code = code.Next @@ -4251,14 +4251,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } else { code = code.NextField } case encoder.OpStructFieldSlice: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p += code.Offset code = code.Next @@ -4270,12 +4270,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if slice.Len == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } case encoder.OpStructFieldSlicePtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) code = code.Next @@ -4284,14 +4284,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } else { code = code.NextField } case encoder.OpStructFieldMap: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToPtr(p + code.Offset) code = code.Next @@ -4302,12 +4302,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 || maplen(ptrToUnsafePtr(p)) == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } case encoder.OpStructFieldMapPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToPtr(p + code.Offset) if p != 0 { @@ -4322,14 +4322,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p = ptrToNPtr(p, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } else { code = code.NextField } case encoder.OpStructFieldStruct: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p += code.Offset code = code.Next @@ -4347,7 +4347,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndInt: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p+code.Offset), code) b = appendStructEnd(b) code = code.Next @@ -4356,7 +4356,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendInt(b, u64, code) b = appendStructEnd(b) } else { @@ -4365,7 +4365,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndIntString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') @@ -4376,7 +4376,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, u64, code) b = append(b, '"') @@ -4386,7 +4386,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndIntPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4400,7 +4400,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p), code) b = appendStructEnd(b) } else { @@ -4408,7 +4408,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndIntPtrString: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4424,7 +4424,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, ptrToUint64(p), code) b = append(b, '"') @@ -4435,7 +4435,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndUint: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p+code.Offset), code) b = appendStructEnd(b) code = code.Next @@ -4444,7 +4444,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendUint(b, u64, code) b = appendStructEnd(b) } else { @@ -4453,7 +4453,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndUintString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') @@ -4464,7 +4464,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, u64, code) b = append(b, '"') @@ -4474,7 +4474,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndUintPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4488,7 +4488,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p), code) b = appendStructEnd(b) } else { @@ -4496,7 +4496,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndUintPtrString: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4512,7 +4512,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, ptrToUint64(p), code) b = append(b, '"') @@ -4523,7 +4523,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndFloat32: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = appendStructEnd(b) code = code.Next @@ -4531,7 +4531,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat32(p + code.Offset) if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, v) b = appendStructEnd(b) } else { @@ -4540,7 +4540,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndFloat32String: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = append(b, '"') @@ -4550,7 +4550,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat32(p + code.Offset) if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, v) b = append(b, '"') @@ -4560,7 +4560,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat32Ptr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4574,7 +4574,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p)) b = appendStructEnd(b) } else { @@ -4582,7 +4582,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat32PtrString: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4598,7 +4598,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p)) b = append(b, '"') @@ -4609,7 +4609,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndFloat64: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p + code.Offset) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -4624,7 +4624,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat64(b, v) b = appendStructEnd(b) } else { @@ -4637,7 +4637,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') @@ -4650,7 +4650,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') @@ -4660,7 +4660,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat64Ptr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4680,7 +4680,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -4692,7 +4692,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat64PtrString: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4712,7 +4712,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -4727,7 +4727,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p+code.Offset)) b = appendStructEnd(b) code = code.Next @@ -4735,7 +4735,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToString(p + code.Offset) if v != "" { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, v) b = appendStructEnd(b) } else { @@ -4744,7 +4744,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndStringString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) s := ptrToString(p + code.Offset) b = appendString(b, string(appendString([]byte{}, s))) b = appendStructEnd(b) @@ -4753,7 +4753,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToString(p + code.Offset) if v != "" { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, v))) b = appendStructEnd(b) } else { @@ -4761,7 +4761,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndStringPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4775,7 +4775,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p)) b = appendStructEnd(b) } else { @@ -4783,7 +4783,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndStringPtrString: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4798,7 +4798,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) v := ptrToString(p) b = appendString(b, string(appendString([]byte{}, v))) b = appendStructEnd(b) @@ -4808,7 +4808,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndBool: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p+code.Offset)) b = appendStructEnd(b) code = code.Next @@ -4816,7 +4816,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBool(p + code.Offset) if v { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendBool(b, v) b = appendStructEnd(b) } else { @@ -4825,7 +4825,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndBoolString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, ptrToBool(p+code.Offset)) b = append(b, '"') @@ -4835,7 +4835,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBool(p + code.Offset) if v { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, v) b = append(b, '"') @@ -4845,7 +4845,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndBoolPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4859,7 +4859,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p)) b = appendStructEnd(b) } else { @@ -4867,7 +4867,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndBoolPtrString: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4883,7 +4883,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, ptrToBool(p)) b = append(b, '"') @@ -4894,7 +4894,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndBytes: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p+code.Offset)) b = appendStructEnd(b) code = code.Next @@ -4902,7 +4902,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBytes(p + code.Offset) if len(v) > 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, v) b = appendStructEnd(b) } else { @@ -4910,7 +4910,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndBytesPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4924,7 +4924,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p)) b = appendStructEnd(b) } else { @@ -4933,7 +4933,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndNumber: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { return nil, err @@ -4944,7 +4944,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToNumber(p + code.Offset) if v != "" { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, v) if err != nil { return nil, err @@ -4956,7 +4956,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndNumberString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { @@ -4969,7 +4969,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToNumber(p + code.Offset) if v != "" { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, v) if err != nil { @@ -4982,7 +4982,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndNumberPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5000,7 +5000,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { return nil, err @@ -5011,7 +5011,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndNumberPtrString: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5030,7 +5030,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { diff --git a/internal/encoder/vm_debug/util.go b/internal/encoder/vm_debug/util.go index 5fc11d6..94f8521 100644 --- a/internal/encoder/vm_debug/util.go +++ b/internal/encoder/vm_debug/util.go @@ -76,6 +76,14 @@ func appendComma(b []byte) []byte { return append(b, ',') } +func appendStructKey(_ *encoder.RuntimeContext, code *encoder.Opcode, b []byte) []byte { + return append(b, code.Key...) +} + +func appendStructHead(b []byte) []byte { + return append(b, '{') +} + func appendStructEnd(b []byte) []byte { return append(b, '}', ',') } diff --git a/internal/encoder/vm_debug/vm.go b/internal/encoder/vm_debug/vm.go index 55b02d2..ce6ec9f 100644 --- a/internal/encoder/vm_debug/vm.go +++ b/internal/encoder/vm_debug/vm.go @@ -600,10 +600,10 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if !code.AnonymousKey { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) } p += code.Offset code = code.Next @@ -631,13 +631,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } p += code.Offset if p == 0 || (ptrToPtr(p) == 0 && code.IsNextOpPtrType) { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -666,9 +666,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p+code.Offset), code) b = appendComma(b) code = code.Next @@ -697,14 +697,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendInt(b, u64, code) b = appendComma(b) code = code.Next @@ -734,9 +734,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') @@ -767,14 +767,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, u64, code) b = append(b, '"') @@ -804,9 +804,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -840,13 +840,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p), code) b = appendComma(b) } @@ -874,9 +874,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -912,13 +912,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, ptrToUint64(p), code) b = append(b, '"') @@ -950,9 +950,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p+code.Offset), code) b = appendComma(b) code = code.Next @@ -981,14 +981,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendUint(b, u64, code) b = appendComma(b) code = code.Next @@ -1018,9 +1018,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') @@ -1051,14 +1051,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, u64, code) b = append(b, '"') @@ -1088,9 +1088,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1124,13 +1124,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p), code) b = appendComma(b) } @@ -1158,9 +1158,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1196,13 +1196,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, ptrToUint64(p), code) b = append(b, '"') @@ -1234,9 +1234,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = appendComma(b) code = code.Next @@ -1265,13 +1265,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToFloat32(p + code.Offset) if v == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, v) b = appendComma(b) code = code.Next @@ -1301,9 +1301,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = append(b, '"') @@ -1334,13 +1334,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToFloat32(p + code.Offset) if v == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, v) b = append(b, '"') @@ -1370,9 +1370,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1406,13 +1406,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p)) b = appendComma(b) } @@ -1440,9 +1440,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1478,13 +1478,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p)) b = append(b, '"') @@ -1520,9 +1520,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt return nil, errUnsupportedFloat(v) } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat64(b, v) b = appendComma(b) code = code.Next @@ -1551,7 +1551,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToFloat64(p + code.Offset) if v == 0 { @@ -1560,7 +1560,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat64(b, v) b = appendComma(b) code = code.Next @@ -1590,13 +1590,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToFloat64(p + code.Offset) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') @@ -1627,7 +1627,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToFloat64(p + code.Offset) if v == 0 { @@ -1636,7 +1636,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') @@ -1666,9 +1666,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1706,13 +1706,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -1744,9 +1744,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1786,13 +1786,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { @@ -1828,9 +1828,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p+code.Offset)) b = appendComma(b) code = code.Next @@ -1859,13 +1859,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToString(p + code.Offset) if v == "" { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, v) b = appendComma(b) code = code.Next @@ -1895,9 +1895,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) s := ptrToString(p + code.Offset) b = appendString(b, string(appendString([]byte{}, s))) b = appendComma(b) @@ -1927,13 +1927,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToString(p + code.Offset) if v == "" { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, v))) b = appendComma(b) code = code.Next @@ -1961,9 +1961,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1997,13 +1997,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p)) b = appendComma(b) } @@ -2031,9 +2031,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2067,13 +2067,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, ptrToString(p)))) b = appendComma(b) } @@ -2103,9 +2103,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p+code.Offset)) b = appendComma(b) code = code.Next @@ -2134,11 +2134,11 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToBool(p + code.Offset) if v { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendBool(b, v) b = appendComma(b) code = code.Next @@ -2170,9 +2170,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, ptrToBool(p+code.Offset)) b = append(b, '"') @@ -2203,11 +2203,11 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToBool(p + code.Offset) if v { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, v) b = append(b, '"') @@ -2239,9 +2239,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2275,13 +2275,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p)) b = appendComma(b) } @@ -2309,9 +2309,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2347,13 +2347,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, ptrToBool(p)) b = append(b, '"') @@ -2385,9 +2385,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p+code.Offset)) b = appendComma(b) code = code.Next @@ -2416,13 +2416,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToBytes(p + code.Offset) if v == nil { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p)) b = appendComma(b) code = code.Next @@ -2450,9 +2450,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2486,13 +2486,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p)) b = appendComma(b) } @@ -2522,9 +2522,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { return nil, err @@ -2556,13 +2556,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToNumber(p + code.Offset) if v == "" { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, v) if err != nil { return nil, err @@ -2595,9 +2595,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { @@ -2631,13 +2631,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToNumber(p + code.Offset) if v == "" { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, v) if err != nil { @@ -2670,9 +2670,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2710,13 +2710,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { return nil, err @@ -2747,9 +2747,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2788,13 +2788,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { @@ -2829,9 +2829,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p += code.Offset code = code.Next store(ctxptr, code.Idx, p) @@ -2860,10 +2860,10 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } p += code.Offset - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) case encoder.OpStructPtrHeadOmitEmptySlice: @@ -2891,14 +2891,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } p += code.Offset slice := ptrToSlice(p) if slice.Len == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -2925,9 +2925,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2962,7 +2962,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) @@ -2970,7 +2970,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -2997,9 +2997,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if p != 0 && code.Indirect { p = ptrToPtr(p + code.Offset) } @@ -3028,7 +3028,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if p != 0 && code.Indirect { p = ptrToPtr(p + code.Offset) @@ -3036,7 +3036,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if maplen(ptrToUnsafePtr(p)) == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -3063,9 +3063,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) b = appendComma(b) @@ -3107,7 +3107,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if p == 0 { code = code.NextField @@ -3120,7 +3120,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if code.Indirect { p = ptrToNPtr(p, code.PtrNum) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -3149,9 +3149,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.IsNilableType { if code.Indirect || code.Op == encoder.OpStructPtrHeadMarshalJSON { p = ptrToPtr(p + code.Offset) @@ -3193,7 +3193,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.IsNilableType { if code.Indirect || code.Op == encoder.OpStructPtrHeadOmitEmptyMarshalJSON { @@ -3204,7 +3204,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if code.Nilcheck && encoder.IsNilForMarshaler(iface) { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalJSON(ctx, code, b, iface, false) if err != nil { return nil, err @@ -3236,9 +3236,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -3279,12 +3279,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p = ptrToNPtr(p+code.Offset, code.PtrNum) } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if p == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), false) if err != nil { return nil, err @@ -3318,9 +3318,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.IsNilableType { if code.Indirect || code.Op == encoder.OpStructPtrHeadMarshalText { p = ptrToPtr(p + code.Offset) @@ -3362,7 +3362,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.IsNilableType { if code.Indirect || code.Op == encoder.OpStructPtrHeadOmitEmptyMarshalText { @@ -3372,7 +3372,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 && code.Nilcheck { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalText(code, b, ptrToInterface(code, p), false) if err != nil { return nil, err @@ -3404,9 +3404,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -3447,12 +3447,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p = ptrToNPtr(p+code.Offset, code.PtrNum) } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if p == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalText(code, b, ptrToInterface(code, p), false) if err != nil { return nil, err @@ -3463,7 +3463,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } case encoder.OpStructField: if !code.AnonymousKey { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) } p := load(ctxptr, code.HeadIdx) + code.Offset code = code.Next @@ -3474,13 +3474,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if ptrToPtr(p) == 0 && code.IsNextOpPtrType { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } case encoder.OpStructFieldInt: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p+code.Offset), code) b = appendComma(b) code = code.Next @@ -3489,14 +3489,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendInt(b, u64, code) b = appendComma(b) } code = code.Next case encoder.OpStructFieldIntString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') @@ -3507,7 +3507,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, u64, code) b = append(b, '"') @@ -3515,7 +3515,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldIntPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3529,7 +3529,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p), code) b = appendComma(b) } @@ -3537,7 +3537,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldIntPtrString: p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3551,7 +3551,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, ptrToUint64(p), code) b = append(b, '"') @@ -3560,7 +3560,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldUint: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p+code.Offset), code) b = appendComma(b) code = code.Next @@ -3569,14 +3569,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendUint(b, u64, code) b = appendComma(b) } code = code.Next case encoder.OpStructFieldUintString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') @@ -3587,7 +3587,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, u64, code) b = append(b, '"') @@ -3595,7 +3595,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldUintPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3609,7 +3609,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p), code) b = appendComma(b) } @@ -3617,7 +3617,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldUintPtrString: p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3631,7 +3631,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, ptrToUint64(p), code) b = append(b, '"') @@ -3640,7 +3640,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldFloat32: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = appendComma(b) code = code.Next @@ -3648,14 +3648,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat32(p + code.Offset) if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, v) b = appendComma(b) } code = code.Next case encoder.OpStructFieldFloat32String: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = append(b, '"') @@ -3665,7 +3665,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat32(p + code.Offset) if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, v) b = append(b, '"') @@ -3673,7 +3673,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldFloat32Ptr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3687,7 +3687,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p)) b = appendComma(b) } @@ -3695,7 +3695,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldFloat32PtrString: p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3709,7 +3709,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p)) b = append(b, '"') @@ -3718,7 +3718,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldFloat64: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p + code.Offset) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -3733,7 +3733,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat64(b, v) b = appendComma(b) } @@ -3744,7 +3744,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') @@ -3757,7 +3757,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') @@ -3765,7 +3765,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldFloat64Ptr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3785,7 +3785,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -3797,7 +3797,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldFloat64PtrString: p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3815,7 +3815,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { @@ -3828,7 +3828,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p+code.Offset)) b = appendComma(b) code = code.Next @@ -3836,14 +3836,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToString(p + code.Offset) if v != "" { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, v) b = appendComma(b) } code = code.Next case encoder.OpStructFieldStringString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) s := ptrToString(p + code.Offset) b = appendString(b, string(appendString([]byte{}, s))) b = appendComma(b) @@ -3852,13 +3852,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToString(p + code.Offset) if v != "" { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, v))) b = appendComma(b) } code = code.Next case encoder.OpStructFieldStringPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3872,13 +3872,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p)) b = appendComma(b) } code = code.Next case encoder.OpStructFieldStringPtrString: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3892,14 +3892,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, ptrToString(p)))) b = appendComma(b) } code = code.Next case encoder.OpStructFieldBool: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p+code.Offset)) b = appendComma(b) code = code.Next @@ -3907,14 +3907,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBool(p + code.Offset) if v { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendBool(b, v) b = appendComma(b) } code = code.Next case encoder.OpStructFieldBoolString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, ptrToBool(p+code.Offset)) b = append(b, '"') @@ -3924,7 +3924,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBool(p + code.Offset) if v { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, v) b = append(b, '"') @@ -3932,7 +3932,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldBoolPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3946,13 +3946,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p)) b = appendComma(b) } code = code.Next case encoder.OpStructFieldBoolPtrString: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3968,7 +3968,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, ptrToBool(p)) b = append(b, '"') @@ -3977,7 +3977,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldBytes: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p+code.Offset)) b = appendComma(b) code = code.Next @@ -3985,13 +3985,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBytes(p + code.Offset) if len(v) > 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, v) b = appendComma(b) } code = code.Next case encoder.OpStructFieldBytesPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4005,14 +4005,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p)) b = appendComma(b) } code = code.Next case encoder.OpStructFieldNumber: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { return nil, err @@ -4023,7 +4023,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToNumber(p + code.Offset) if v != "" { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, v) if err != nil { return nil, err @@ -4033,7 +4033,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldNumberString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { @@ -4046,7 +4046,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToNumber(p + code.Offset) if v != "" { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, v) if err != nil { @@ -4057,7 +4057,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldNumberPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4075,7 +4075,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { return nil, err @@ -4084,7 +4084,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldNumberPtrString: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4103,7 +4103,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { @@ -4115,7 +4115,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldMarshalJSON: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p += code.Offset if code.IsNilableType { p = ptrToPtr(p) @@ -4146,7 +4146,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.NextField break } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalJSON(ctx, code, b, iface, false) if err != nil { return nil, err @@ -4155,7 +4155,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldMarshalJSONPtr: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { b = appendNull(b) @@ -4172,7 +4172,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), false) if err != nil { return nil, err @@ -4182,7 +4182,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldMarshalText: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p += code.Offset if code.IsNilableType { p = ptrToPtr(p) @@ -4208,7 +4208,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.NextField break } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalText(code, b, ptrToInterface(code, p), false) if err != nil { return nil, err @@ -4217,7 +4217,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldMarshalTextPtr: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { b = appendNull(b) @@ -4234,7 +4234,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalText(code, b, ptrToInterface(code, p), false) if err != nil { return nil, err @@ -4243,7 +4243,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldArray: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p += code.Offset code = code.Next @@ -4251,11 +4251,11 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldOmitEmptyArray: p := load(ctxptr, code.HeadIdx) p += code.Offset - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) case encoder.OpStructFieldArrayPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) code = code.Next @@ -4264,14 +4264,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } else { code = code.NextField } case encoder.OpStructFieldSlice: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p += code.Offset code = code.Next @@ -4283,12 +4283,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if slice.Len == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } case encoder.OpStructFieldSlicePtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) code = code.Next @@ -4297,14 +4297,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } else { code = code.NextField } case encoder.OpStructFieldMap: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToPtr(p + code.Offset) code = code.Next @@ -4315,12 +4315,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 || maplen(ptrToUnsafePtr(p)) == 0 { code = code.NextField } else { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } case encoder.OpStructFieldMapPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToPtr(p + code.Offset) if p != 0 { @@ -4335,14 +4335,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p = ptrToNPtr(p, code.PtrNum) } if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } else { code = code.NextField } case encoder.OpStructFieldStruct: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p += code.Offset code = code.Next @@ -4360,7 +4360,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndInt: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p+code.Offset), code) b = appendStructEnd(b) code = code.Next @@ -4369,7 +4369,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendInt(b, u64, code) b = appendStructEnd(b) } else { @@ -4378,7 +4378,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndIntString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') @@ -4389,7 +4389,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, u64, code) b = append(b, '"') @@ -4399,7 +4399,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndIntPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4413,7 +4413,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p), code) b = appendStructEnd(b) } else { @@ -4421,7 +4421,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndIntPtrString: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4437,7 +4437,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, ptrToUint64(p), code) b = append(b, '"') @@ -4448,7 +4448,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndUint: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p+code.Offset), code) b = appendStructEnd(b) code = code.Next @@ -4457,7 +4457,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendUint(b, u64, code) b = appendStructEnd(b) } else { @@ -4466,7 +4466,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndUintString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') @@ -4477,7 +4477,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, u64, code) b = append(b, '"') @@ -4487,7 +4487,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndUintPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4501,7 +4501,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p), code) b = appendStructEnd(b) } else { @@ -4509,7 +4509,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndUintPtrString: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4525,7 +4525,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, ptrToUint64(p), code) b = append(b, '"') @@ -4536,7 +4536,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndFloat32: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = appendStructEnd(b) code = code.Next @@ -4544,7 +4544,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat32(p + code.Offset) if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, v) b = appendStructEnd(b) } else { @@ -4553,7 +4553,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndFloat32String: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = append(b, '"') @@ -4563,7 +4563,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat32(p + code.Offset) if v != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, v) b = append(b, '"') @@ -4573,7 +4573,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat32Ptr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4587,7 +4587,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p)) b = appendStructEnd(b) } else { @@ -4595,7 +4595,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat32PtrString: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4611,7 +4611,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p)) b = append(b, '"') @@ -4622,7 +4622,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndFloat64: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p + code.Offset) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -4637,7 +4637,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendFloat64(b, v) b = appendStructEnd(b) } else { @@ -4650,7 +4650,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') @@ -4663,7 +4663,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') @@ -4673,7 +4673,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat64Ptr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4693,7 +4693,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -4705,7 +4705,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat64PtrString: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4725,7 +4725,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -4740,7 +4740,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p+code.Offset)) b = appendStructEnd(b) code = code.Next @@ -4748,7 +4748,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToString(p + code.Offset) if v != "" { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, v) b = appendStructEnd(b) } else { @@ -4757,7 +4757,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndStringString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) s := ptrToString(p + code.Offset) b = appendString(b, string(appendString([]byte{}, s))) b = appendStructEnd(b) @@ -4766,7 +4766,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToString(p + code.Offset) if v != "" { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, v))) b = appendStructEnd(b) } else { @@ -4774,7 +4774,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndStringPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4788,7 +4788,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p)) b = appendStructEnd(b) } else { @@ -4796,7 +4796,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndStringPtrString: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4811,7 +4811,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) v := ptrToString(p) b = appendString(b, string(appendString([]byte{}, v))) b = appendStructEnd(b) @@ -4821,7 +4821,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndBool: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p+code.Offset)) b = appendStructEnd(b) code = code.Next @@ -4829,7 +4829,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBool(p + code.Offset) if v { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendBool(b, v) b = appendStructEnd(b) } else { @@ -4838,7 +4838,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndBoolString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, ptrToBool(p+code.Offset)) b = append(b, '"') @@ -4848,7 +4848,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBool(p + code.Offset) if v { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, v) b = append(b, '"') @@ -4858,7 +4858,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndBoolPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4872,7 +4872,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p)) b = appendStructEnd(b) } else { @@ -4880,7 +4880,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndBoolPtrString: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4896,7 +4896,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, ptrToBool(p)) b = append(b, '"') @@ -4907,7 +4907,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndBytes: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p+code.Offset)) b = appendStructEnd(b) code = code.Next @@ -4915,7 +4915,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBytes(p + code.Offset) if len(v) > 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, v) b = appendStructEnd(b) } else { @@ -4923,7 +4923,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndBytesPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4937,7 +4937,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p)) b = appendStructEnd(b) } else { @@ -4946,7 +4946,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndNumber: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { return nil, err @@ -4957,7 +4957,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToNumber(p + code.Offset) if v != "" { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, v) if err != nil { return nil, err @@ -4969,7 +4969,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndNumberString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { @@ -4982,7 +4982,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToNumber(p + code.Offset) if v != "" { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, v) if err != nil { @@ -4995,7 +4995,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndNumberPtr: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5013,7 +5013,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { return nil, err @@ -5024,7 +5024,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndNumberPtrString: - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5043,7 +5043,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.Key...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { diff --git a/internal/encoder/vm_escaped/util.go b/internal/encoder/vm_escaped/util.go index c7a335a..07765a7 100644 --- a/internal/encoder/vm_escaped/util.go +++ b/internal/encoder/vm_escaped/util.go @@ -76,6 +76,14 @@ func appendComma(b []byte) []byte { return append(b, ',') } +func appendStructHead(b []byte) []byte { + return append(b, '{') +} + +func appendStructKey(_ *encoder.RuntimeContext, code *encoder.Opcode, b []byte) []byte { + return append(b, code.EscapedKey...) +} + func appendStructEnd(b []byte) []byte { return append(b, '}', ',') } diff --git a/internal/encoder/vm_escaped/vm.go b/internal/encoder/vm_escaped/vm.go index 55947ec..f65920f 100644 --- a/internal/encoder/vm_escaped/vm.go +++ b/internal/encoder/vm_escaped/vm.go @@ -587,10 +587,10 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if !code.AnonymousKey { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) } p += code.Offset code = code.Next @@ -618,13 +618,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } p += code.Offset if p == 0 || (ptrToPtr(p) == 0 && code.IsNextOpPtrType) { code = code.NextField } else { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -653,9 +653,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p+code.Offset), code) b = appendComma(b) code = code.Next @@ -684,14 +684,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v == 0 { code = code.NextField } else { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendInt(b, u64, code) b = appendComma(b) code = code.Next @@ -721,9 +721,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') @@ -754,14 +754,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v == 0 { code = code.NextField } else { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, u64, code) b = append(b, '"') @@ -791,9 +791,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -827,13 +827,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p), code) b = appendComma(b) } @@ -861,9 +861,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -899,13 +899,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, ptrToUint64(p), code) b = append(b, '"') @@ -937,9 +937,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p+code.Offset), code) b = appendComma(b) code = code.Next @@ -968,14 +968,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v == 0 { code = code.NextField } else { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendUint(b, u64, code) b = appendComma(b) code = code.Next @@ -1005,9 +1005,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') @@ -1038,14 +1038,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v == 0 { code = code.NextField } else { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, u64, code) b = append(b, '"') @@ -1075,9 +1075,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1111,13 +1111,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p), code) b = appendComma(b) } @@ -1145,9 +1145,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1183,13 +1183,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, ptrToUint64(p), code) b = append(b, '"') @@ -1221,9 +1221,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = appendComma(b) code = code.Next @@ -1252,13 +1252,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToFloat32(p + code.Offset) if v == 0 { code = code.NextField } else { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, v) b = appendComma(b) code = code.Next @@ -1288,9 +1288,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = append(b, '"') @@ -1321,13 +1321,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToFloat32(p + code.Offset) if v == 0 { code = code.NextField } else { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, v) b = append(b, '"') @@ -1357,9 +1357,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1393,13 +1393,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p)) b = appendComma(b) } @@ -1427,9 +1427,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1465,13 +1465,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p)) b = append(b, '"') @@ -1507,9 +1507,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt return nil, errUnsupportedFloat(v) } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendFloat64(b, v) b = appendComma(b) code = code.Next @@ -1538,7 +1538,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToFloat64(p + code.Offset) if v == 0 { @@ -1547,7 +1547,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendFloat64(b, v) b = appendComma(b) code = code.Next @@ -1577,13 +1577,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToFloat64(p + code.Offset) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') @@ -1614,7 +1614,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToFloat64(p + code.Offset) if v == 0 { @@ -1623,7 +1623,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') @@ -1653,9 +1653,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1693,13 +1693,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -1731,9 +1731,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1773,13 +1773,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { @@ -1815,9 +1815,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p+code.Offset)) b = appendComma(b) code = code.Next @@ -1846,13 +1846,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToString(p + code.Offset) if v == "" { code = code.NextField } else { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendString(b, v) b = appendComma(b) code = code.Next @@ -1882,9 +1882,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) s := ptrToString(p + code.Offset) b = appendString(b, string(appendString([]byte{}, s))) b = appendComma(b) @@ -1914,13 +1914,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToString(p + code.Offset) if v == "" { code = code.NextField } else { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, v))) b = appendComma(b) code = code.Next @@ -1948,9 +1948,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1984,13 +1984,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p)) b = appendComma(b) } @@ -2018,9 +2018,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2054,13 +2054,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, ptrToString(p)))) b = appendComma(b) } @@ -2090,9 +2090,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p+code.Offset)) b = appendComma(b) code = code.Next @@ -2121,11 +2121,11 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToBool(p + code.Offset) if v { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendBool(b, v) b = appendComma(b) code = code.Next @@ -2157,9 +2157,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, ptrToBool(p+code.Offset)) b = append(b, '"') @@ -2190,11 +2190,11 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToBool(p + code.Offset) if v { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, v) b = append(b, '"') @@ -2226,9 +2226,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2262,13 +2262,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p)) b = appendComma(b) } @@ -2296,9 +2296,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2334,13 +2334,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, ptrToBool(p)) b = append(b, '"') @@ -2372,9 +2372,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p+code.Offset)) b = appendComma(b) code = code.Next @@ -2403,13 +2403,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToBytes(p + code.Offset) if v == nil { code = code.NextField } else { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p)) b = appendComma(b) code = code.Next @@ -2437,9 +2437,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2473,13 +2473,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p)) b = appendComma(b) } @@ -2509,9 +2509,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { return nil, err @@ -2543,13 +2543,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToNumber(p + code.Offset) if v == "" { code = code.NextField } else { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, v) if err != nil { return nil, err @@ -2582,9 +2582,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { @@ -2618,13 +2618,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } v := ptrToNumber(p + code.Offset) if v == "" { code = code.NextField } else { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, v) if err != nil { @@ -2657,9 +2657,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2697,13 +2697,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { return nil, err @@ -2734,9 +2734,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2775,13 +2775,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { @@ -2816,9 +2816,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p += code.Offset code = code.Next store(ctxptr, code.Idx, p) @@ -2847,10 +2847,10 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } p += code.Offset - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) case encoder.OpStructPtrHeadOmitEmptySlice: @@ -2878,14 +2878,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } p += code.Offset slice := ptrToSlice(p) if slice.Len == 0 { code = code.NextField } else { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -2912,9 +2912,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2949,7 +2949,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) @@ -2957,7 +2957,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 { code = code.NextField } else { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -2984,9 +2984,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if p != 0 && code.Indirect { p = ptrToPtr(p + code.Offset) } @@ -3015,7 +3015,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if p != 0 && code.Indirect { p = ptrToPtr(p + code.Offset) @@ -3023,7 +3023,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if maplen(ptrToUnsafePtr(p)) == 0 { code = code.NextField } else { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -3050,9 +3050,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) b = appendComma(b) @@ -3094,7 +3094,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if p == 0 { code = code.NextField @@ -3107,7 +3107,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if code.Indirect { p = ptrToNPtr(p, code.PtrNum) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -3136,9 +3136,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if code.IsNilableType { if code.Indirect || code.Op == encoder.OpStructPtrHeadMarshalJSON { p = ptrToPtr(p + code.Offset) @@ -3180,7 +3180,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.IsNilableType { if code.Indirect || code.Op == encoder.OpStructPtrHeadOmitEmptyMarshalJSON { @@ -3191,7 +3191,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if code.Nilcheck && encoder.IsNilForMarshaler(iface) { code = code.NextField } else { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalJSON(ctx, code, b, iface, true) if err != nil { return nil, err @@ -3223,9 +3223,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -3266,12 +3266,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p = ptrToNPtr(p+code.Offset, code.PtrNum) } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if p == 0 { code = code.NextField } else { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), true) if err != nil { return nil, err @@ -3305,9 +3305,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if code.IsNilableType { if code.Indirect || code.Op == encoder.OpStructPtrHeadMarshalText { p = ptrToPtr(p + code.Offset) @@ -3349,7 +3349,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if code.IsNilableType { if code.Indirect || code.Op == encoder.OpStructPtrHeadOmitEmptyMarshalText { @@ -3359,7 +3359,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 && code.Nilcheck { code = code.NextField } else { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalText(code, b, ptrToInterface(code, p), true) if err != nil { return nil, err @@ -3391,9 +3391,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -3434,12 +3434,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p = ptrToNPtr(p+code.Offset, code.PtrNum) } if !code.AnonymousHead { - b = append(b, '{') + b = appendStructHead(b) } if p == 0 { code = code.NextField } else { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalText(code, b, ptrToInterface(code, p), true) if err != nil { return nil, err @@ -3450,7 +3450,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } case encoder.OpStructField: if !code.AnonymousKey { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) } p := load(ctxptr, code.HeadIdx) + code.Offset code = code.Next @@ -3461,13 +3461,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if ptrToPtr(p) == 0 && code.IsNextOpPtrType { code = code.NextField } else { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } case encoder.OpStructFieldInt: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p+code.Offset), code) b = appendComma(b) code = code.Next @@ -3476,14 +3476,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendInt(b, u64, code) b = appendComma(b) } code = code.Next case encoder.OpStructFieldIntString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') @@ -3494,7 +3494,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, u64, code) b = append(b, '"') @@ -3502,7 +3502,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldIntPtr: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3516,7 +3516,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p), code) b = appendComma(b) } @@ -3524,7 +3524,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldIntPtrString: p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3538,7 +3538,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, ptrToUint64(p), code) b = append(b, '"') @@ -3547,7 +3547,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldUint: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p+code.Offset), code) b = appendComma(b) code = code.Next @@ -3556,14 +3556,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendUint(b, u64, code) b = appendComma(b) } code = code.Next case encoder.OpStructFieldUintString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') @@ -3574,7 +3574,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, u64, code) b = append(b, '"') @@ -3582,7 +3582,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldUintPtr: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3596,7 +3596,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p), code) b = appendComma(b) } @@ -3604,7 +3604,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldUintPtrString: p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3618,7 +3618,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, ptrToUint64(p), code) b = append(b, '"') @@ -3627,7 +3627,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldFloat32: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = appendComma(b) code = code.Next @@ -3635,14 +3635,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat32(p + code.Offset) if v != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, v) b = appendComma(b) } code = code.Next case encoder.OpStructFieldFloat32String: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = append(b, '"') @@ -3652,7 +3652,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat32(p + code.Offset) if v != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, v) b = append(b, '"') @@ -3660,7 +3660,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldFloat32Ptr: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3674,7 +3674,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p)) b = appendComma(b) } @@ -3682,7 +3682,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldFloat32PtrString: p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3696,7 +3696,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p)) b = append(b, '"') @@ -3705,7 +3705,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldFloat64: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p + code.Offset) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -3720,7 +3720,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendFloat64(b, v) b = appendComma(b) } @@ -3731,7 +3731,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') @@ -3744,7 +3744,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') @@ -3752,7 +3752,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldFloat64Ptr: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3772,7 +3772,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -3784,7 +3784,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldFloat64PtrString: p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3802,7 +3802,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { @@ -3815,7 +3815,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p+code.Offset)) b = appendComma(b) code = code.Next @@ -3823,14 +3823,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToString(p + code.Offset) if v != "" { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendString(b, v) b = appendComma(b) } code = code.Next case encoder.OpStructFieldStringString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) s := ptrToString(p + code.Offset) b = appendString(b, string(appendString([]byte{}, s))) b = appendComma(b) @@ -3839,13 +3839,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToString(p + code.Offset) if v != "" { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, v))) b = appendComma(b) } code = code.Next case encoder.OpStructFieldStringPtr: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3859,13 +3859,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p)) b = appendComma(b) } code = code.Next case encoder.OpStructFieldStringPtrString: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3879,14 +3879,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, ptrToString(p)))) b = appendComma(b) } code = code.Next case encoder.OpStructFieldBool: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p+code.Offset)) b = appendComma(b) code = code.Next @@ -3894,14 +3894,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBool(p + code.Offset) if v { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendBool(b, v) b = appendComma(b) } code = code.Next case encoder.OpStructFieldBoolString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, ptrToBool(p+code.Offset)) b = append(b, '"') @@ -3911,7 +3911,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBool(p + code.Offset) if v { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, v) b = append(b, '"') @@ -3919,7 +3919,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldBoolPtr: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3933,13 +3933,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p)) b = appendComma(b) } code = code.Next case encoder.OpStructFieldBoolPtrString: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3955,7 +3955,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, ptrToBool(p)) b = append(b, '"') @@ -3964,7 +3964,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldBytes: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p+code.Offset)) b = appendComma(b) code = code.Next @@ -3972,13 +3972,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBytes(p + code.Offset) if len(v) > 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, v) b = appendComma(b) } code = code.Next case encoder.OpStructFieldBytesPtr: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -3992,14 +3992,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p)) b = appendComma(b) } code = code.Next case encoder.OpStructFieldNumber: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { return nil, err @@ -4010,7 +4010,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToNumber(p + code.Offset) if v != "" { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, v) if err != nil { return nil, err @@ -4020,7 +4020,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldNumberString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { @@ -4033,7 +4033,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToNumber(p + code.Offset) if v != "" { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, v) if err != nil { @@ -4044,7 +4044,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldNumberPtr: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4062,7 +4062,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { return nil, err @@ -4071,7 +4071,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldNumberPtrString: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4090,7 +4090,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { @@ -4102,7 +4102,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldMarshalJSON: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p += code.Offset if code.IsNilableType { p = ptrToPtr(p) @@ -4133,7 +4133,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.NextField break } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalJSON(ctx, code, b, iface, true) if err != nil { return nil, err @@ -4142,7 +4142,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldMarshalJSONPtr: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { b = appendNull(b) @@ -4159,7 +4159,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), true) if err != nil { return nil, err @@ -4169,7 +4169,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldMarshalText: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p += code.Offset if code.IsNilableType { p = ptrToPtr(p) @@ -4195,7 +4195,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.NextField break } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalText(code, b, ptrToInterface(code, p), true) if err != nil { return nil, err @@ -4204,7 +4204,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldMarshalTextPtr: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { b = appendNull(b) @@ -4221,7 +4221,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) bb, err := appendMarshalText(code, b, ptrToInterface(code, p), true) if err != nil { return nil, err @@ -4230,7 +4230,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldArray: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p += code.Offset code = code.Next @@ -4238,11 +4238,11 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldOmitEmptyArray: p := load(ctxptr, code.HeadIdx) p += code.Offset - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) case encoder.OpStructFieldArrayPtr: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) code = code.Next @@ -4251,14 +4251,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } else { code = code.NextField } case encoder.OpStructFieldSlice: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p += code.Offset code = code.Next @@ -4270,12 +4270,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if slice.Len == 0 { code = code.NextField } else { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } case encoder.OpStructFieldSlicePtr: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) code = code.Next @@ -4284,14 +4284,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } else { code = code.NextField } case encoder.OpStructFieldMap: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToPtr(p + code.Offset) code = code.Next @@ -4302,12 +4302,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 || maplen(ptrToUnsafePtr(p)) == 0 { code = code.NextField } else { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } case encoder.OpStructFieldMapPtr: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToPtr(p + code.Offset) if p != 0 { @@ -4322,14 +4322,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p = ptrToNPtr(p, code.PtrNum) } if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } else { code = code.NextField } case encoder.OpStructFieldStruct: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p += code.Offset code = code.Next @@ -4347,7 +4347,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndInt: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p+code.Offset), code) b = appendStructEnd(b) code = code.Next @@ -4356,7 +4356,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendInt(b, u64, code) b = appendStructEnd(b) } else { @@ -4365,7 +4365,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndIntString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') @@ -4376,7 +4376,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, u64, code) b = append(b, '"') @@ -4386,7 +4386,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndIntPtr: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4400,7 +4400,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p), code) b = appendStructEnd(b) } else { @@ -4408,7 +4408,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndIntPtrString: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4424,7 +4424,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendInt(b, ptrToUint64(p), code) b = append(b, '"') @@ -4435,7 +4435,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndUint: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p+code.Offset), code) b = appendStructEnd(b) code = code.Next @@ -4444,7 +4444,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendUint(b, u64, code) b = appendStructEnd(b) } else { @@ -4453,7 +4453,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndUintString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') @@ -4464,7 +4464,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, u64, code) b = append(b, '"') @@ -4474,7 +4474,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndUintPtr: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4488,7 +4488,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p), code) b = appendStructEnd(b) } else { @@ -4496,7 +4496,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndUintPtrString: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4512,7 +4512,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendUint(b, ptrToUint64(p), code) b = append(b, '"') @@ -4523,7 +4523,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndFloat32: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = appendStructEnd(b) code = code.Next @@ -4531,7 +4531,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat32(p + code.Offset) if v != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, v) b = appendStructEnd(b) } else { @@ -4540,7 +4540,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndFloat32String: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = append(b, '"') @@ -4550,7 +4550,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat32(p + code.Offset) if v != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, v) b = append(b, '"') @@ -4560,7 +4560,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat32Ptr: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4574,7 +4574,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p)) b = appendStructEnd(b) } else { @@ -4582,7 +4582,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat32PtrString: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4598,7 +4598,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p)) b = append(b, '"') @@ -4609,7 +4609,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndFloat64: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p + code.Offset) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -4624,7 +4624,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendFloat64(b, v) b = appendStructEnd(b) } else { @@ -4637,7 +4637,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') @@ -4650,7 +4650,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') @@ -4660,7 +4660,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat64Ptr: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4680,7 +4680,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -4692,7 +4692,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat64PtrString: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4712,7 +4712,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -4727,7 +4727,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p+code.Offset)) b = appendStructEnd(b) code = code.Next @@ -4735,7 +4735,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToString(p + code.Offset) if v != "" { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendString(b, v) b = appendStructEnd(b) } else { @@ -4744,7 +4744,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndStringString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) s := ptrToString(p + code.Offset) b = appendString(b, string(appendString([]byte{}, s))) b = appendStructEnd(b) @@ -4753,7 +4753,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToString(p + code.Offset) if v != "" { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, v))) b = appendStructEnd(b) } else { @@ -4761,7 +4761,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndStringPtr: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4775,7 +4775,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p)) b = appendStructEnd(b) } else { @@ -4783,7 +4783,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndStringPtrString: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4798,7 +4798,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) v := ptrToString(p) b = appendString(b, string(appendString([]byte{}, v))) b = appendStructEnd(b) @@ -4808,7 +4808,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndBool: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p+code.Offset)) b = appendStructEnd(b) code = code.Next @@ -4816,7 +4816,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBool(p + code.Offset) if v { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendBool(b, v) b = appendStructEnd(b) } else { @@ -4825,7 +4825,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndBoolString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, ptrToBool(p+code.Offset)) b = append(b, '"') @@ -4835,7 +4835,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBool(p + code.Offset) if v { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, v) b = append(b, '"') @@ -4845,7 +4845,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndBoolPtr: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4859,7 +4859,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p)) b = appendStructEnd(b) } else { @@ -4867,7 +4867,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndBoolPtrString: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4883,7 +4883,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') b = appendBool(b, ptrToBool(p)) b = append(b, '"') @@ -4894,7 +4894,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndBytes: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p+code.Offset)) b = appendStructEnd(b) code = code.Next @@ -4902,7 +4902,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBytes(p + code.Offset) if len(v) > 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, v) b = appendStructEnd(b) } else { @@ -4910,7 +4910,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndBytesPtr: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4924,7 +4924,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p)) b = appendStructEnd(b) } else { @@ -4933,7 +4933,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndNumber: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { return nil, err @@ -4944,7 +4944,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToNumber(p + code.Offset) if v != "" { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, v) if err != nil { return nil, err @@ -4956,7 +4956,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndNumberString: p := load(ctxptr, code.HeadIdx) - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { @@ -4969,7 +4969,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToNumber(p + code.Offset) if v != "" { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, v) if err != nil { @@ -4982,7 +4982,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndNumberPtr: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5000,7 +5000,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { return nil, err @@ -5011,7 +5011,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndNumberPtrString: - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5030,7 +5030,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = append(b, code.EscapedKey...) + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { diff --git a/internal/encoder/vm_escaped_indent/util.go b/internal/encoder/vm_escaped_indent/util.go index eba9a48..6f427b1 100644 --- a/internal/encoder/vm_escaped_indent/util.go +++ b/internal/encoder/vm_escaped_indent/util.go @@ -76,6 +76,16 @@ func appendComma(b []byte) []byte { return append(b, ',', '\n') } +func appendStructHead(b []byte) []byte { + return append(b, '{', '\n') +} + +func appendStructKey(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte) []byte { + b = appendIndent(ctx, b, code.Indent) + b = append(b, code.EscapedKey...) + return append(b, ' ') +} + func appendStructEndSkipLast(ctx *encoder.RuntimeContext, b []byte, code *encoder.Opcode) []byte { last := len(b) - 1 if b[last-1] == '{' { diff --git a/internal/encoder/vm_escaped_indent/vm.go b/internal/encoder/vm_escaped_indent/vm.go index 786abef..752b541 100644 --- a/internal/encoder/vm_escaped_indent/vm.go +++ b/internal/encoder/vm_escaped_indent/vm.go @@ -430,7 +430,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.End.Next break } - b = append(b, '{', '\n') + b = appendStructHead(b) iter := mapiterinit(code.Type, uptr) ctx.KeepRefs = append(ctx.KeepRefs, iter) store(ctxptr, code.ElemIdx, 0) @@ -610,12 +610,10 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - if !code.AnonymousKey && len(code.Key) > 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + if !code.AnonymousKey && len(code.EscapedKey) > 0 { + b = appendStructKey(ctx, code, b) } p += code.Offset code = code.Next @@ -643,15 +641,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } p += code.Offset if p == 0 || (ptrToPtr(p) == 0 && code.IsNextOpPtrType) { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -680,11 +676,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p+code.Offset), code) b = appendComma(b) code = code.Next @@ -713,16 +707,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendInt(b, u64, code) b = appendComma(b) code = code.Next @@ -752,11 +744,10 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendInt(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') b = appendComma(b) @@ -786,16 +777,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendInt(b, u64, code) b = append(b, '"') b = appendComma(b) @@ -824,11 +814,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -862,15 +850,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p), code) b = appendComma(b) } @@ -898,11 +884,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -938,15 +922,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendInt(b, ptrToUint64(p), code) b = append(b, '"') b = appendComma(b) @@ -977,11 +960,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p+code.Offset), code) b = appendComma(b) code = code.Next @@ -1010,16 +991,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendUint(b, u64, code) b = appendComma(b) code = code.Next @@ -1049,11 +1028,10 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendUint(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') b = appendComma(b) @@ -1083,16 +1061,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendUint(b, u64, code) b = append(b, '"') b = appendComma(b) @@ -1121,11 +1098,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1159,15 +1134,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p), code) b = appendComma(b) } @@ -1195,11 +1168,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1235,15 +1206,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendUint(b, ptrToUint64(p), code) b = append(b, '"') b = appendComma(b) @@ -1274,11 +1244,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = appendComma(b) code = code.Next @@ -1307,15 +1275,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } v := ptrToFloat32(p + code.Offset) if v == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendFloat32(b, v) b = appendComma(b) code = code.Next @@ -1345,11 +1311,10 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = append(b, '"') b = appendComma(b) @@ -1379,15 +1344,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } v := ptrToFloat32(p + code.Offset) if v == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat32(b, v) b = append(b, '"') b = appendComma(b) @@ -1416,11 +1380,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p, code.PtrNum) } @@ -1454,15 +1416,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p)) b = appendComma(b) } @@ -1490,11 +1450,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1530,15 +1488,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p)) b = append(b, '"') b = appendComma(b) @@ -1573,11 +1530,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt return nil, errUnsupportedFloat(v) } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendFloat64(b, v) b = appendComma(b) code = code.Next @@ -1606,7 +1561,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } v := ptrToFloat64(p + code.Offset) if math.IsInf(v, 0) || math.IsNaN(v) { @@ -1615,9 +1570,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if v == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendFloat64(b, v) b = appendComma(b) code = code.Next @@ -1647,11 +1600,10 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') v := ptrToFloat64(p + code.Offset) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -1685,7 +1637,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } v := ptrToFloat64(p + code.Offset) if math.IsInf(v, 0) || math.IsNaN(v) { @@ -1694,9 +1646,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if v == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') b = appendComma(b) @@ -1725,11 +1676,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1767,15 +1716,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -1807,11 +1754,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1851,15 +1796,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -1894,11 +1838,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p+code.Offset)) b = appendComma(b) code = code.Next @@ -1927,15 +1869,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } v := ptrToString(p + code.Offset) if v == "" { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, v) b = appendComma(b) code = code.Next @@ -1965,11 +1905,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) v := ptrToString(p + code.Offset) b = appendString(b, string(appendString([]byte{}, v))) b = appendComma(b) @@ -1999,15 +1937,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } v := ptrToString(p + code.Offset) if v == "" { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, v))) b = appendComma(b) code = code.Next @@ -2035,11 +1971,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2073,15 +2007,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p)) b = appendComma(b) } @@ -2109,11 +2041,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2147,15 +2077,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, ptrToString(p)))) b = appendComma(b) } @@ -2185,11 +2113,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p+code.Offset)) b = appendComma(b) code = code.Next @@ -2218,13 +2144,11 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } v := ptrToBool(p + code.Offset) if v { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendBool(b, v) b = appendComma(b) code = code.Next @@ -2256,11 +2180,10 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendBool(b, ptrToBool(p+code.Offset)) b = append(b, '"') b = appendComma(b) @@ -2290,13 +2213,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } v := ptrToBool(p + code.Offset) if v { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendBool(b, v) b = append(b, '"') b = appendComma(b) @@ -2327,11 +2249,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p, code.PtrNum) } @@ -2365,15 +2285,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p)) b = appendComma(b) } @@ -2401,11 +2319,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2441,15 +2357,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendBool(b, ptrToBool(p)) b = append(b, '"') b = appendComma(b) @@ -2480,11 +2395,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p+code.Offset)) b = appendComma(b) code = code.Next @@ -2513,15 +2426,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } v := ptrToBytes(p + code.Offset) if len(v) == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, v) b = appendComma(b) code = code.Next @@ -2549,11 +2460,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2587,15 +2496,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p)) b = appendComma(b) } @@ -2625,11 +2532,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { return nil, err @@ -2661,15 +2566,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } v := ptrToNumber(p + code.Offset) if v == "" { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, v) if err != nil { return nil, err @@ -2702,11 +2605,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { @@ -2740,15 +2641,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } v := ptrToNumber(p + code.Offset) if v == "" { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') bb, err := appendNumber(b, v) if err != nil { return nil, err @@ -2780,11 +2680,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2822,15 +2720,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { return nil, err @@ -2861,11 +2757,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2904,15 +2798,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { return nil, err @@ -2946,11 +2839,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p += code.Offset code = code.Next store(ctxptr, code.Idx, p) @@ -2979,12 +2870,10 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } p += code.Offset - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) case encoder.OpStructPtrHeadOmitEmptySlice: @@ -3012,16 +2901,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } p += code.Offset slice := ptrToSlice(p) if slice.Len == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -3048,11 +2935,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -3087,7 +2972,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) @@ -3095,9 +2980,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -3124,11 +3007,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if p != 0 && code.Indirect { p = ptrToPtr(p + code.Offset) } @@ -3157,7 +3038,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if p != 0 && code.Indirect { p = ptrToPtr(p + code.Offset) @@ -3165,9 +3046,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if maplen(ptrToUnsafePtr(p)) == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -3194,11 +3073,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) b = appendComma(b) @@ -3240,7 +3117,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if p == 0 { code = code.NextField @@ -3253,9 +3130,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if code.Indirect { p = ptrToNPtr(p, code.PtrNum) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -3284,11 +3159,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.IsNilableType { if code.Indirect || code.Op == encoder.OpStructPtrHeadMarshalJSON { p = ptrToPtr(p + code.Offset) @@ -3297,7 +3170,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 && code.Nilcheck { b = appendNull(b) } else { - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, true) if err != nil { return nil, err } @@ -3330,7 +3203,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.IsNilableType { if code.Indirect || code.Op == encoder.OpStructPtrHeadOmitEmptyMarshalJSON { @@ -3341,10 +3214,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if code.Nilcheck && encoder.IsNilForMarshaler(iface) { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') - bb, err := appendMarshalJSON(ctx, code, b, iface, code.Indent+1, true) + b = appendStructKey(ctx, code, b) + bb, err := appendMarshalJSON(ctx, code, b, iface, code.Indent, true) if err != nil { return nil, err } @@ -3375,18 +3246,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p == 0 { b = appendNull(b) } else { - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, true) if err != nil { return nil, err } @@ -3420,15 +3289,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p = ptrToNPtr(p+code.Offset, code.PtrNum) } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if p == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true) + b = appendStructKey(ctx, code, b) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, true) if err != nil { return nil, err } @@ -3461,11 +3328,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.IsNilableType { if code.Indirect || code.Op == encoder.OpStructPtrHeadMarshalText { p = ptrToPtr(p + code.Offset) @@ -3507,7 +3372,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.IsNilableType { if code.Indirect || code.Op == encoder.OpStructPtrHeadOmitEmptyMarshalText { @@ -3517,9 +3382,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 && code.Nilcheck { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) bb, err := appendMarshalText(code, b, ptrToInterface(code, p), true) if err != nil { return nil, err @@ -3551,11 +3414,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -3596,14 +3457,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p = ptrToNPtr(p+code.Offset, code.PtrNum) } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if p == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) bb, err := appendMarshalText(code, b, ptrToInterface(code, p), true) if err != nil { return nil, err @@ -3614,9 +3473,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } case encoder.OpStructField: if !code.AnonymousKey { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) } p := load(ctxptr, code.HeadIdx) + code.Offset code = code.Next @@ -3627,17 +3484,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if ptrToPtr(p) == 0 && code.IsNextOpPtrType { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } case encoder.OpStructFieldInt: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p+code.Offset), code) b = appendComma(b) code = code.Next @@ -3646,18 +3499,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendInt(b, u64, code) b = appendComma(b) } code = code.Next case encoder.OpStructFieldIntString: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendInt(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') b = appendComma(b) @@ -3667,20 +3517,17 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendInt(b, u64, code) b = append(b, '"') b = appendComma(b) } code = code.Next case encoder.OpStructFieldIntPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3692,9 +3539,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p), code) b = appendComma(b) } @@ -3702,9 +3547,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldIntPtrString: p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3718,19 +3561,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendInt(b, ptrToUint64(p), code) b = append(b, '"') b = appendComma(b) } code = code.Next case encoder.OpStructFieldUint: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p+code.Offset), code) b = appendComma(b) code = code.Next @@ -3739,18 +3579,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendUint(b, u64, code) b = appendComma(b) } code = code.Next case encoder.OpStructFieldUintString: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendUint(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') b = appendComma(b) @@ -3760,20 +3597,17 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendUint(b, u64, code) b = append(b, '"') b = appendComma(b) } code = code.Next case encoder.OpStructFieldUintPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3785,9 +3619,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p), code) b = appendComma(b) } @@ -3795,9 +3627,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldUintPtrString: p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3811,19 +3641,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendUint(b, ptrToUint64(p), code) b = append(b, '"') b = appendComma(b) } code = code.Next case encoder.OpStructFieldFloat32: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = appendComma(b) code = code.Next @@ -3831,18 +3658,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat32(p + code.Offset) if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendFloat32(b, v) b = appendComma(b) } code = code.Next case encoder.OpStructFieldFloat32String: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = append(b, '"') b = appendComma(b) @@ -3851,20 +3675,17 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat32(p + code.Offset) if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat32(b, v) b = append(b, '"') b = appendComma(b) } code = code.Next case encoder.OpStructFieldFloat32Ptr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3876,9 +3697,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p)) b = appendComma(b) } @@ -3886,9 +3705,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldFloat32PtrString: p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3902,19 +3719,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p)) b = append(b, '"') b = appendComma(b) } code = code.Next case encoder.OpStructFieldFloat64: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p + code.Offset) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -3929,9 +3743,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendFloat64(b, v) b = appendComma(b) } @@ -3942,9 +3754,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') b = appendComma(b) @@ -3956,20 +3767,17 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') b = appendComma(b) } code = code.Next case encoder.OpStructFieldFloat64Ptr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3985,9 +3793,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -3999,9 +3805,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldFloat64PtrString: p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -4019,9 +3823,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -4032,10 +3835,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p+code.Offset)) b = appendComma(b) code = code.Next @@ -4043,19 +3844,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToString(p + code.Offset) if v != "" { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, v) b = appendComma(b) } code = code.Next case encoder.OpStructFieldStringString: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') s := ptrToString(p + code.Offset) + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, s))) b = appendComma(b) code = code.Next @@ -4063,19 +3860,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToString(p + code.Offset) if v != "" { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, v))) b = appendComma(b) } code = code.Next case encoder.OpStructFieldStringPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -4087,19 +3880,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p)) b = appendComma(b) } code = code.Next case encoder.OpStructFieldStringPtrString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -4111,18 +3900,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, ptrToString(p)))) b = appendComma(b) } code = code.Next case encoder.OpStructFieldBool: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p+code.Offset)) b = appendComma(b) code = code.Next @@ -4130,18 +3915,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBool(p + code.Offset) if v { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendBool(b, v) b = appendComma(b) } code = code.Next case encoder.OpStructFieldBoolString: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendBool(b, ptrToBool(p+code.Offset)) b = append(b, '"') b = appendComma(b) @@ -4150,20 +3932,17 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBool(p + code.Offset) if v { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendBool(b, v) b = append(b, '"') b = appendComma(b) } code = code.Next case encoder.OpStructFieldBoolPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -4175,19 +3954,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p)) b = appendComma(b) } code = code.Next case encoder.OpStructFieldBoolPtrString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -4201,19 +3976,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendBool(b, ptrToBool(p)) b = append(b, '"') b = appendComma(b) } code = code.Next case encoder.OpStructFieldBytes: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p+code.Offset)) b = appendComma(b) code = code.Next @@ -4221,19 +3993,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBytes(p + code.Offset) if len(v) > 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, v) b = appendComma(b) } code = code.Next case encoder.OpStructFieldBytesPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -4245,18 +4013,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p)) b = appendComma(b) } code = code.Next case encoder.OpStructFieldNumber: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { return nil, err @@ -4267,9 +4031,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToNumber(p + code.Offset) if v != "" { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, v) if err != nil { return nil, err @@ -4278,11 +4040,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldNumberString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') - b = append(b, '"') p := load(ctxptr, code.HeadIdx) + b = appendStructKey(ctx, code, b) + b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { return nil, err @@ -4294,9 +4054,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToNumber(p + code.Offset) if v != "" { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') bb, err := appendNumber(b, v) if err != nil { return nil, err @@ -4306,11 +4065,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldNumberPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -4326,9 +4083,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { return nil, err @@ -4337,11 +4092,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldNumberPtrString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -4358,9 +4111,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { return nil, err @@ -4370,10 +4122,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldMarshalJSON: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) + b = appendStructKey(ctx, code, b) p += code.Offset if code.IsNilableType { p = ptrToPtr(p) @@ -4381,7 +4131,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 && code.Nilcheck { b = appendNull(b) } else { - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, true) if err != nil { return nil, err } @@ -4404,10 +4154,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.NextField break } - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') - bb, err := appendMarshalJSON(ctx, code, b, iface, code.Indent+1, true) + b = appendStructKey(ctx, code, b) + bb, err := appendMarshalJSON(ctx, code, b, iface, code.Indent, true) if err != nil { return nil, err } @@ -4415,14 +4163,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldMarshalJSONPtr: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { b = appendNull(b) } else { - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, true) if err != nil { return nil, err } @@ -4434,10 +4180,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true) + b = appendStructKey(ctx, code, b) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, true) if err != nil { return nil, err } @@ -4446,9 +4190,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldMarshalText: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p += code.Offset if code.IsNilableType { p = ptrToPtr(p) @@ -4474,9 +4216,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.NextField break } - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) bb, err := appendMarshalText(code, b, ptrToInterface(code, p), true) if err != nil { return nil, err @@ -4485,9 +4225,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldMarshalTextPtr: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { b = appendNull(b) @@ -4504,9 +4242,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) bb, err := appendMarshalText(code, b, ptrToInterface(code, p), true) if err != nil { return nil, err @@ -4515,25 +4251,19 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldArray: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p += code.Offset code = code.Next store(ctxptr, code.Idx, p) case encoder.OpStructFieldOmitEmptyArray: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p += code.Offset code = code.Next store(ctxptr, code.Idx, p) case encoder.OpStructFieldArrayPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) code = code.Next @@ -4542,18 +4272,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } else { code = code.NextField } case encoder.OpStructFieldSlice: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p += code.Offset code = code.Next @@ -4565,16 +4291,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if slice.Len == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } case encoder.OpStructFieldSlicePtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) code = code.Next @@ -4583,18 +4305,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } else { code = code.NextField } case encoder.OpStructFieldMap: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToPtr(p + code.Offset) code = code.Next @@ -4605,16 +4323,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 || maplen(ptrToUnsafePtr(p)) == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } case encoder.OpStructFieldMapPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToPtr(p + code.Offset) if p != 0 { @@ -4629,9 +4343,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p = ptrToNPtr(p, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } else { @@ -4640,9 +4352,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldStruct: p := load(ctxptr, code.HeadIdx) p += code.Offset - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) case encoder.OpStructFieldOmitEmptyStruct: @@ -4651,9 +4361,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if ptrToPtr(p) == 0 && code.IsNextOpPtrType { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -4677,9 +4385,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt b = appendComma(b) code = code.Next case encoder.OpStructEndInt: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) b = appendInt(b, ptrToUint64(p+code.Offset), code) b = appendStructEnd(ctx, b, code.Indent-1) @@ -4689,9 +4395,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendInt(b, u64, code) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -4700,9 +4404,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndIntString: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendInt(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -4712,9 +4415,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendInt(b, u64, code) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -4723,9 +4425,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndIntPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4739,9 +4439,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p), code) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -4749,9 +4447,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndIntPtrString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4767,9 +4463,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendInt(b, ptrToUint64(p), code) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -4778,9 +4473,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndUint: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) b = appendUint(b, ptrToUint64(p+code.Offset), code) b = appendStructEnd(ctx, b, code.Indent-1) @@ -4790,9 +4483,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendUint(b, u64, code) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -4801,9 +4492,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndUintString: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendUint(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -4813,9 +4503,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendUint(b, u64, code) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -4824,9 +4513,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndUintPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4840,9 +4527,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p), code) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -4850,9 +4535,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndUintPtrString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4868,9 +4551,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendUint(b, ptrToUint64(p), code) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -4879,9 +4561,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat32: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = appendStructEnd(ctx, b, code.Indent-1) @@ -4890,9 +4570,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat32(p + code.Offset) if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendFloat32(b, v) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -4901,9 +4579,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndFloat32String: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -4912,9 +4589,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat32(p + code.Offset) if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat32(b, v) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -4923,9 +4599,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat32Ptr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4939,9 +4613,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p)) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -4949,9 +4621,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat32PtrString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4967,9 +4637,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p)) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -4978,9 +4647,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat64: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) v := ptrToFloat64(p + code.Offset) if math.IsInf(v, 0) || math.IsNaN(v) { @@ -4993,9 +4660,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat64(p + code.Offset) if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } @@ -5011,9 +4676,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -5022,9 +4686,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat64(p + code.Offset) if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } @@ -5036,9 +4699,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat64Ptr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5056,9 +4717,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -5070,9 +4729,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat64PtrString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5092,9 +4749,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -5107,9 +4763,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) b = appendString(b, ptrToString(p+code.Offset)) b = appendStructEnd(ctx, b, code.Indent-1) @@ -5118,9 +4772,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToString(p + code.Offset) if v != "" { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, v) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -5129,9 +4781,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndStringString: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) s := ptrToString(p + code.Offset) b = appendString(b, string(appendString([]byte{}, s))) b = appendStructEnd(ctx, b, code.Indent-1) @@ -5140,9 +4790,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToString(p + code.Offset) if v != "" { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, v))) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -5150,9 +4798,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndStringPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5166,9 +4812,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p)) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -5176,9 +4820,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndStringPtrString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5192,9 +4834,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, ptrToString(p)))) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -5202,9 +4842,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndBool: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) b = appendBool(b, ptrToBool(p+code.Offset)) b = appendStructEnd(ctx, b, code.Indent-1) @@ -5213,9 +4851,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBool(p + code.Offset) if v { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendBool(b, v) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -5224,9 +4860,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndBoolString: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendBool(b, ptrToBool(p+code.Offset)) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -5235,9 +4870,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBool(p + code.Offset) if v { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendBool(b, v) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -5246,9 +4880,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndBoolPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5262,9 +4894,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p)) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -5272,9 +4902,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndBoolPtrString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5290,9 +4918,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendBool(b, ptrToBool(p)) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -5301,9 +4928,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndBytes: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) b = appendByteSlice(b, ptrToBytes(p+code.Offset)) b = appendStructEnd(ctx, b, code.Indent-1) @@ -5312,9 +4937,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBytes(p + code.Offset) if len(v) > 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, v) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -5322,9 +4945,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndBytesPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5338,9 +4959,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p)) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -5348,9 +4967,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndNumber: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { @@ -5362,9 +4979,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToNumber(p + code.Offset) if v != "" { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, v) if err != nil { return nil, err @@ -5375,9 +4990,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndNumberString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = append(b, '"') p := load(ctxptr, code.HeadIdx) bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) @@ -5391,9 +5004,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToNumber(p + code.Offset) if v != "" { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') bb, err := appendNumber(b, v) if err != nil { return nil, err @@ -5405,9 +5017,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndNumberPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5425,9 +5035,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { return nil, err @@ -5438,9 +5046,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndNumberPtrString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5459,9 +5065,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.EscapedKey...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { return nil, err diff --git a/internal/encoder/vm_indent/util.go b/internal/encoder/vm_indent/util.go index d9d74c6..a20ca12 100644 --- a/internal/encoder/vm_indent/util.go +++ b/internal/encoder/vm_indent/util.go @@ -76,6 +76,16 @@ func appendComma(b []byte) []byte { return append(b, ',', '\n') } +func appendStructHead(b []byte) []byte { + return append(b, '{', '\n') +} + +func appendStructKey(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte) []byte { + b = appendIndent(ctx, b, code.Indent) + b = append(b, code.Key...) + return append(b, ' ') +} + func appendStructEndSkipLast(ctx *encoder.RuntimeContext, b []byte, code *encoder.Opcode) []byte { last := len(b) - 1 if b[last-1] == '{' { diff --git a/internal/encoder/vm_indent/vm.go b/internal/encoder/vm_indent/vm.go index 17933f1..31ce1e4 100644 --- a/internal/encoder/vm_indent/vm.go +++ b/internal/encoder/vm_indent/vm.go @@ -430,7 +430,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.End.Next break } - b = append(b, '{', '\n') + b = appendStructHead(b) iter := mapiterinit(code.Type, uptr) ctx.KeepRefs = append(ctx.KeepRefs, iter) store(ctxptr, code.ElemIdx, 0) @@ -610,12 +610,10 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if !code.AnonymousKey && len(code.Key) > 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) } p += code.Offset code = code.Next @@ -643,15 +641,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } p += code.Offset if p == 0 || (ptrToPtr(p) == 0 && code.IsNextOpPtrType) { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -680,11 +676,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p+code.Offset), code) b = appendComma(b) code = code.Next @@ -713,16 +707,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendInt(b, u64, code) b = appendComma(b) code = code.Next @@ -752,11 +744,10 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendInt(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') b = appendComma(b) @@ -786,16 +777,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendInt(b, u64, code) b = append(b, '"') b = appendComma(b) @@ -824,11 +814,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -862,15 +850,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p), code) b = appendComma(b) } @@ -898,11 +884,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -938,15 +922,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendInt(b, ptrToUint64(p), code) b = append(b, '"') b = appendComma(b) @@ -977,11 +960,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p+code.Offset), code) b = appendComma(b) code = code.Next @@ -1010,16 +991,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendUint(b, u64, code) b = appendComma(b) code = code.Next @@ -1049,11 +1028,10 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendUint(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') b = appendComma(b) @@ -1083,16 +1061,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendUint(b, u64, code) b = append(b, '"') b = appendComma(b) @@ -1121,11 +1098,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1159,15 +1134,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p), code) b = appendComma(b) } @@ -1195,11 +1168,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1235,15 +1206,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendUint(b, ptrToUint64(p), code) b = append(b, '"') b = appendComma(b) @@ -1274,11 +1244,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = appendComma(b) code = code.Next @@ -1307,15 +1275,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } v := ptrToFloat32(p + code.Offset) if v == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendFloat32(b, v) b = appendComma(b) code = code.Next @@ -1345,11 +1311,10 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = append(b, '"') b = appendComma(b) @@ -1379,15 +1344,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } v := ptrToFloat32(p + code.Offset) if v == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat32(b, v) b = append(b, '"') b = appendComma(b) @@ -1416,11 +1380,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p, code.PtrNum) } @@ -1454,15 +1416,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p)) b = appendComma(b) } @@ -1490,11 +1450,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1530,15 +1488,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p)) b = append(b, '"') b = appendComma(b) @@ -1573,11 +1530,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt return nil, errUnsupportedFloat(v) } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendFloat64(b, v) b = appendComma(b) code = code.Next @@ -1606,7 +1561,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } v := ptrToFloat64(p + code.Offset) if math.IsInf(v, 0) || math.IsNaN(v) { @@ -1615,9 +1570,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if v == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendFloat64(b, v) b = appendComma(b) code = code.Next @@ -1647,11 +1600,10 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') v := ptrToFloat64(p + code.Offset) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -1685,7 +1637,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } v := ptrToFloat64(p + code.Offset) if math.IsInf(v, 0) || math.IsNaN(v) { @@ -1694,9 +1646,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if v == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') b = appendComma(b) @@ -1725,11 +1676,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1767,15 +1716,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -1807,11 +1754,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -1851,15 +1796,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -1894,11 +1838,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p+code.Offset)) b = appendComma(b) code = code.Next @@ -1927,15 +1869,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } v := ptrToString(p + code.Offset) if v == "" { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, v) b = appendComma(b) code = code.Next @@ -1965,11 +1905,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) v := ptrToString(p + code.Offset) b = appendString(b, string(appendString([]byte{}, v))) b = appendComma(b) @@ -1999,15 +1937,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } v := ptrToString(p + code.Offset) if v == "" { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, v))) b = appendComma(b) code = code.Next @@ -2035,11 +1971,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2073,15 +2007,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p)) b = appendComma(b) } @@ -2109,11 +2041,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2147,15 +2077,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, ptrToString(p)))) b = appendComma(b) } @@ -2185,11 +2113,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p+code.Offset)) b = appendComma(b) code = code.Next @@ -2218,13 +2144,11 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } v := ptrToBool(p + code.Offset) if v { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendBool(b, v) b = appendComma(b) code = code.Next @@ -2256,11 +2180,10 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendBool(b, ptrToBool(p+code.Offset)) b = append(b, '"') b = appendComma(b) @@ -2290,13 +2213,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } v := ptrToBool(p + code.Offset) if v { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendBool(b, v) b = append(b, '"') b = appendComma(b) @@ -2327,11 +2249,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p, code.PtrNum) } @@ -2365,15 +2285,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p)) b = appendComma(b) } @@ -2401,11 +2319,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2441,15 +2357,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendBool(b, ptrToBool(p)) b = append(b, '"') b = appendComma(b) @@ -2480,11 +2395,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p+code.Offset)) b = appendComma(b) code = code.Next @@ -2513,15 +2426,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } v := ptrToBytes(p + code.Offset) if len(v) == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, v) b = appendComma(b) code = code.Next @@ -2549,11 +2460,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2587,15 +2496,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p)) b = appendComma(b) } @@ -2625,11 +2532,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { return nil, err @@ -2661,15 +2566,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } v := ptrToNumber(p + code.Offset) if v == "" { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, v) if err != nil { return nil, err @@ -2702,11 +2605,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { @@ -2740,15 +2641,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } v := ptrToNumber(p + code.Offset) if v == "" { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') bb, err := appendNumber(b, v) if err != nil { return nil, err @@ -2780,11 +2680,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2822,15 +2720,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { return nil, err @@ -2861,11 +2757,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -2904,15 +2798,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { return nil, err @@ -2946,11 +2839,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p += code.Offset code = code.Next store(ctxptr, code.Idx, p) @@ -2979,12 +2870,10 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } p += code.Offset - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) case encoder.OpStructPtrHeadOmitEmptySlice: @@ -3012,16 +2901,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } p += code.Offset slice := ptrToSlice(p) if slice.Len == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -3048,11 +2935,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -3087,7 +2972,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) @@ -3095,9 +2980,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -3124,11 +3007,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if p != 0 && code.Indirect { p = ptrToPtr(p + code.Offset) } @@ -3157,7 +3038,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if p != 0 && code.Indirect { p = ptrToPtr(p + code.Offset) @@ -3165,9 +3046,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if maplen(ptrToUnsafePtr(p)) == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -3194,11 +3073,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) b = appendComma(b) @@ -3240,7 +3117,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if p == 0 { code = code.NextField @@ -3253,9 +3130,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if code.Indirect { p = ptrToNPtr(p, code.PtrNum) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -3284,11 +3159,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.IsNilableType { if code.Indirect || code.Op == encoder.OpStructPtrHeadMarshalJSON { p = ptrToPtr(p + code.Offset) @@ -3297,7 +3170,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 && code.Nilcheck { b = appendNull(b) } else { - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, false) if err != nil { return nil, err } @@ -3330,7 +3203,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.IsNilableType { if code.Indirect || code.Op == encoder.OpStructPtrHeadOmitEmptyMarshalJSON { @@ -3341,10 +3214,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if code.Nilcheck && encoder.IsNilForMarshaler(iface) { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') - bb, err := appendMarshalJSON(ctx, code, b, iface, code.Indent+1, false) + b = appendStructKey(ctx, code, b) + bb, err := appendMarshalJSON(ctx, code, b, iface, code.Indent, false) if err != nil { return nil, err } @@ -3375,18 +3246,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } if p == 0 { b = appendNull(b) } else { - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, false) if err != nil { return nil, err } @@ -3420,15 +3289,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p = ptrToNPtr(p+code.Offset, code.PtrNum) } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if p == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false) + b = appendStructKey(ctx, code, b) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, false) if err != nil { return nil, err } @@ -3461,11 +3328,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.IsNilableType { if code.Indirect || code.Op == encoder.OpStructPtrHeadMarshalText { p = ptrToPtr(p + code.Offset) @@ -3507,7 +3372,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if code.IsNilableType { if code.Indirect || code.Op == encoder.OpStructPtrHeadOmitEmptyMarshalText { @@ -3517,9 +3382,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 && code.Nilcheck { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) bb, err := appendMarshalText(code, b, ptrToInterface(code, p), false) if err != nil { return nil, err @@ -3551,11 +3414,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt break } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if code.Indirect { p = ptrToNPtr(p+code.Offset, code.PtrNum) } @@ -3596,14 +3457,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p = ptrToNPtr(p+code.Offset, code.PtrNum) } if !code.AnonymousHead { - b = append(b, '{', '\n') + b = appendStructHead(b) } if p == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent+1) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) bb, err := appendMarshalText(code, b, ptrToInterface(code, p), false) if err != nil { return nil, err @@ -3614,9 +3473,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } case encoder.OpStructField: if !code.AnonymousKey { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) } p := load(ctxptr, code.HeadIdx) + code.Offset code = code.Next @@ -3627,17 +3484,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if ptrToPtr(p) == 0 && code.IsNextOpPtrType { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } case encoder.OpStructFieldInt: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p+code.Offset), code) b = appendComma(b) code = code.Next @@ -3646,18 +3499,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendInt(b, u64, code) b = appendComma(b) } code = code.Next case encoder.OpStructFieldIntString: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendInt(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') b = appendComma(b) @@ -3667,20 +3517,17 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendInt(b, u64, code) b = append(b, '"') b = appendComma(b) } code = code.Next case encoder.OpStructFieldIntPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3692,9 +3539,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p), code) b = appendComma(b) } @@ -3702,9 +3547,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldIntPtrString: p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3718,19 +3561,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendInt(b, ptrToUint64(p), code) b = append(b, '"') b = appendComma(b) } code = code.Next case encoder.OpStructFieldUint: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p+code.Offset), code) b = appendComma(b) code = code.Next @@ -3739,18 +3579,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendUint(b, u64, code) b = appendComma(b) } code = code.Next case encoder.OpStructFieldUintString: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendUint(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') b = appendComma(b) @@ -3760,20 +3597,17 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendUint(b, u64, code) b = append(b, '"') b = appendComma(b) } code = code.Next case encoder.OpStructFieldUintPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3785,9 +3619,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p), code) b = appendComma(b) } @@ -3795,9 +3627,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldUintPtrString: p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3811,19 +3641,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendUint(b, ptrToUint64(p), code) b = append(b, '"') b = appendComma(b) } code = code.Next case encoder.OpStructFieldFloat32: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = appendComma(b) code = code.Next @@ -3831,18 +3658,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat32(p + code.Offset) if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendFloat32(b, v) b = appendComma(b) } code = code.Next case encoder.OpStructFieldFloat32String: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = append(b, '"') b = appendComma(b) @@ -3851,20 +3675,17 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat32(p + code.Offset) if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat32(b, v) b = append(b, '"') b = appendComma(b) } code = code.Next case encoder.OpStructFieldFloat32Ptr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3876,9 +3697,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p)) b = appendComma(b) } @@ -3886,9 +3705,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldFloat32PtrString: p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3902,19 +3719,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p)) b = append(b, '"') b = appendComma(b) } code = code.Next case encoder.OpStructFieldFloat64: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p + code.Offset) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -3929,9 +3743,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendFloat64(b, v) b = appendComma(b) } @@ -3942,9 +3754,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') b = appendComma(b) @@ -3956,20 +3767,17 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') b = appendComma(b) } code = code.Next case encoder.OpStructFieldFloat64Ptr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -3985,9 +3793,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -3999,9 +3805,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldFloat64PtrString: p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -4019,9 +3823,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -4032,10 +3835,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p+code.Offset)) b = appendComma(b) code = code.Next @@ -4043,19 +3844,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToString(p + code.Offset) if v != "" { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, v) b = appendComma(b) } code = code.Next case encoder.OpStructFieldStringString: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') s := ptrToString(p + code.Offset) + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, s))) b = appendComma(b) code = code.Next @@ -4063,19 +3860,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToString(p + code.Offset) if v != "" { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, v))) b = appendComma(b) } code = code.Next case encoder.OpStructFieldStringPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -4087,19 +3880,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p)) b = appendComma(b) } code = code.Next case encoder.OpStructFieldStringPtrString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -4111,18 +3900,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, ptrToString(p)))) b = appendComma(b) } code = code.Next case encoder.OpStructFieldBool: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p+code.Offset)) b = appendComma(b) code = code.Next @@ -4130,18 +3915,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBool(p + code.Offset) if v { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendBool(b, v) b = appendComma(b) } code = code.Next case encoder.OpStructFieldBoolString: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendBool(b, ptrToBool(p+code.Offset)) b = append(b, '"') b = appendComma(b) @@ -4150,20 +3932,17 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBool(p + code.Offset) if v { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendBool(b, v) b = append(b, '"') b = appendComma(b) } code = code.Next case encoder.OpStructFieldBoolPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -4175,19 +3954,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p)) b = appendComma(b) } code = code.Next case encoder.OpStructFieldBoolPtrString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -4201,19 +3976,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendBool(b, ptrToBool(p)) b = append(b, '"') b = appendComma(b) } code = code.Next case encoder.OpStructFieldBytes: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p+code.Offset)) b = appendComma(b) code = code.Next @@ -4221,19 +3993,15 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBytes(p + code.Offset) if len(v) > 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, v) b = appendComma(b) } code = code.Next case encoder.OpStructFieldBytesPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -4245,18 +4013,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p)) b = appendComma(b) } code = code.Next case encoder.OpStructFieldNumber: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { return nil, err @@ -4267,9 +4031,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToNumber(p + code.Offset) if v != "" { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, v) if err != nil { return nil, err @@ -4278,11 +4040,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldNumberString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') - b = append(b, '"') p := load(ctxptr, code.HeadIdx) + b = appendStructKey(ctx, code, b) + b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { return nil, err @@ -4294,9 +4054,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToNumber(p + code.Offset) if v != "" { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') bb, err := appendNumber(b, v) if err != nil { return nil, err @@ -4306,11 +4065,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldNumberPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -4326,9 +4083,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { return nil, err @@ -4337,11 +4092,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldNumberPtrString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) + b = appendStructKey(ctx, code, b) if p == 0 { b = appendNull(b) } else { @@ -4358,9 +4111,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { return nil, err @@ -4370,10 +4122,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldMarshalJSON: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') p := load(ctxptr, code.HeadIdx) + b = appendStructKey(ctx, code, b) p += code.Offset if code.IsNilableType { p = ptrToPtr(p) @@ -4381,7 +4131,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 && code.Nilcheck { b = appendNull(b) } else { - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, false) if err != nil { return nil, err } @@ -4404,10 +4154,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.NextField break } - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') - bb, err := appendMarshalJSON(ctx, code, b, iface, code.Indent+1, false) + b = appendStructKey(ctx, code, b) + bb, err := appendMarshalJSON(ctx, code, b, iface, code.Indent, false) if err != nil { return nil, err } @@ -4415,14 +4163,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldMarshalJSONPtr: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { b = appendNull(b) } else { - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, false) if err != nil { return nil, err } @@ -4434,10 +4180,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false) + b = appendStructKey(ctx, code, b) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, false) if err != nil { return nil, err } @@ -4446,9 +4190,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldMarshalText: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p += code.Offset if code.IsNilableType { p = ptrToPtr(p) @@ -4474,9 +4216,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.NextField break } - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) bb, err := appendMarshalText(code, b, ptrToInterface(code, p), false) if err != nil { return nil, err @@ -4485,9 +4225,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructFieldMarshalTextPtr: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { b = appendNull(b) @@ -4504,9 +4242,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) bb, err := appendMarshalText(code, b, ptrToInterface(code, p), false) if err != nil { return nil, err @@ -4515,25 +4251,19 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructFieldArray: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p += code.Offset code = code.Next store(ctxptr, code.Idx, p) case encoder.OpStructFieldOmitEmptyArray: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p += code.Offset code = code.Next store(ctxptr, code.Idx, p) case encoder.OpStructFieldArrayPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) code = code.Next @@ -4542,18 +4272,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } else { code = code.NextField } case encoder.OpStructFieldSlice: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p += code.Offset code = code.Next @@ -4565,16 +4291,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if slice.Len == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } case encoder.OpStructFieldSlicePtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) code = code.Next @@ -4583,18 +4305,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } else { code = code.NextField } case encoder.OpStructFieldMap: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToPtr(p + code.Offset) code = code.Next @@ -4605,16 +4323,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 || maplen(ptrToUnsafePtr(p)) == 0 { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } case encoder.OpStructFieldMapPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToPtr(p + code.Offset) if p != 0 { @@ -4629,9 +4343,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p = ptrToNPtr(p, code.PtrNum) } if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } else { @@ -4640,9 +4352,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt case encoder.OpStructFieldStruct: p := load(ctxptr, code.HeadIdx) p += code.Offset - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) case encoder.OpStructFieldOmitEmptyStruct: @@ -4651,9 +4361,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if ptrToPtr(p) == 0 && code.IsNextOpPtrType { code = code.NextField } else { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) code = code.Next store(ctxptr, code.Idx, p) } @@ -4677,9 +4385,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt b = appendComma(b) code = code.Next case encoder.OpStructEndInt: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) b = appendInt(b, ptrToUint64(p+code.Offset), code) b = appendStructEnd(ctx, b, code.Indent-1) @@ -4689,9 +4395,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendInt(b, u64, code) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -4700,9 +4404,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndIntString: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendInt(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -4712,9 +4415,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendInt(b, u64, code) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -4723,9 +4425,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndIntPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4739,9 +4439,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendInt(b, ptrToUint64(p), code) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -4749,9 +4447,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndIntPtrString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4767,9 +4463,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendInt(b, ptrToUint64(p), code) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -4778,9 +4473,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndUint: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) b = appendUint(b, ptrToUint64(p+code.Offset), code) b = appendStructEnd(ctx, b, code.Indent-1) @@ -4790,9 +4483,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendUint(b, u64, code) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -4801,9 +4492,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndUintString: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendUint(b, ptrToUint64(p+code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -4813,9 +4503,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt u64 := ptrToUint64(p + code.Offset) v := u64 & code.Mask if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendUint(b, u64, code) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -4824,9 +4513,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndUintPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4840,9 +4527,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendUint(b, ptrToUint64(p), code) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -4850,9 +4535,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndUintPtrString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4868,9 +4551,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendUint(b, ptrToUint64(p), code) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -4879,9 +4561,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat32: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = appendStructEnd(ctx, b, code.Indent-1) @@ -4890,9 +4570,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat32(p + code.Offset) if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendFloat32(b, v) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -4901,9 +4579,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndFloat32String: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p+code.Offset)) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -4912,9 +4589,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat32(p + code.Offset) if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat32(b, v) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -4923,9 +4599,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat32Ptr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4939,9 +4613,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendFloat32(b, ptrToFloat32(p)) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -4949,9 +4621,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat32PtrString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -4967,9 +4637,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat32(b, ptrToFloat32(p)) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -4978,9 +4647,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat64: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) v := ptrToFloat64(p + code.Offset) if math.IsInf(v, 0) || math.IsNaN(v) { @@ -4993,9 +4660,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat64(p + code.Offset) if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } @@ -5011,9 +4676,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendFloat64(b, v) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -5022,9 +4686,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToFloat64(p + code.Offset) if v != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) } @@ -5036,9 +4699,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat64Ptr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5056,9 +4717,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -5070,9 +4729,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndFloat64PtrString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5092,9 +4749,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') v := ptrToFloat64(p) if math.IsInf(v, 0) || math.IsNaN(v) { return nil, errUnsupportedFloat(v) @@ -5107,9 +4763,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) b = appendString(b, ptrToString(p+code.Offset)) b = appendStructEnd(ctx, b, code.Indent-1) @@ -5118,9 +4772,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToString(p + code.Offset) if v != "" { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, v) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -5129,9 +4781,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndStringString: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) s := ptrToString(p + code.Offset) b = appendString(b, string(appendString([]byte{}, s))) b = appendStructEnd(ctx, b, code.Indent-1) @@ -5140,9 +4790,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToString(p + code.Offset) if v != "" { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, v))) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -5150,9 +4798,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndStringPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5166,9 +4812,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, ptrToString(p)) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -5176,9 +4820,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndStringPtrString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5192,9 +4834,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendString(b, string(appendString([]byte{}, ptrToString(p)))) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -5202,9 +4842,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndBool: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) b = appendBool(b, ptrToBool(p+code.Offset)) b = appendStructEnd(ctx, b, code.Indent-1) @@ -5213,9 +4851,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBool(p + code.Offset) if v { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendBool(b, v) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -5224,9 +4860,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next case encoder.OpStructEndBoolString: p := load(ctxptr, code.HeadIdx) - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendBool(b, ptrToBool(p+code.Offset)) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -5235,9 +4870,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBool(p + code.Offset) if v { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendBool(b, v) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -5246,9 +4880,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndBoolPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5262,9 +4894,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendBool(b, ptrToBool(p)) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -5272,9 +4902,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndBoolPtrString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5290,9 +4918,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') b = appendBool(b, ptrToBool(p)) b = append(b, '"') b = appendStructEnd(ctx, b, code.Indent-1) @@ -5301,9 +4928,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndBytes: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) b = appendByteSlice(b, ptrToBytes(p+code.Offset)) b = appendStructEnd(ctx, b, code.Indent-1) @@ -5312,9 +4937,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToBytes(p + code.Offset) if len(v) > 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, v) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -5322,9 +4945,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndBytesPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5338,9 +4959,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = appendByteSlice(b, ptrToBytes(p)) b = appendStructEnd(ctx, b, code.Indent-1) } else { @@ -5348,9 +4967,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndNumber: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) if err != nil { @@ -5362,9 +4979,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToNumber(p + code.Offset) if v != "" { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, v) if err != nil { return nil, err @@ -5375,9 +4990,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndNumberString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) b = append(b, '"') p := load(ctxptr, code.HeadIdx) bb, err := appendNumber(b, ptrToNumber(p+code.Offset)) @@ -5391,9 +5004,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) v := ptrToNumber(p + code.Offset) if v != "" { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') bb, err := appendNumber(b, v) if err != nil { return nil, err @@ -5405,9 +5017,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndNumberPtr: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5425,9 +5035,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { return nil, err @@ -5438,9 +5046,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt } code = code.Next case encoder.OpStructEndNumberPtrString: - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ') + b = appendStructKey(ctx, code, b) p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p == 0 { @@ -5459,9 +5065,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt p := load(ctxptr, code.HeadIdx) p = ptrToNPtr(p+code.Offset, code.PtrNum) if p != 0 { - b = appendIndent(ctx, b, code.Indent) - b = append(b, code.Key...) - b = append(b, ' ', '"') + b = appendStructKey(ctx, code, b) + b = append(b, '"') bb, err := appendNumber(b, ptrToNumber(p)) if err != nil { return nil, err