From ddc486cc62ac6858d8cadbd721ecb195968c717e Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Mon, 15 Feb 2021 12:57:16 +0900 Subject: [PATCH] Add opcode for bool type to the encoder --- encode_vm.go | 535 ++++++++++++++++++++++++------ encode_vm_escaped.go | 553 ++++++++++++++++++++++++------- encode_vm_escaped_indent.go | 625 +++++++++++++++++++++++++++++++----- encode_vm_indent.go | 625 +++++++++++++++++++++++++++++++----- 4 files changed, 1952 insertions(+), 386 deletions(-) diff --git a/encode_vm.go b/encode_vm.go index d66a872..667b220 100644 --- a/encode_vm.go +++ b/encode_vm.go @@ -6449,6 +6449,158 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco b = encodeComma(b) code = code.next case opStructFieldPtrHeadBool: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadBool: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + b = append(b, code.key...) + b = encodeBool(b, ptrToBool(ptr+code.offset)) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrHeadOmitEmptyBool: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyBool: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := ptrToBool(ptr + code.offset) + if v { + b = append(b, code.key...) + b = encodeBool(b, v) + b = encodeComma(b) + code = code.next + } else { + code = code.nextField + } + } + case opStructFieldPtrHeadStringTagBool: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagBool: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + b = append(b, code.key...) + b = append(b, '"') + b = encodeBool(b, ptrToBool(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrHeadBoolOnly, opStructFieldHeadBoolOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + b = encodeBool(b, ptrToBool(p)) + b = encodeComma(b) + code = code.next + case opStructFieldPtrHeadOmitEmptyBoolOnly, opStructFieldHeadOmitEmptyBoolOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := ptrToBool(p) + if v { + b = append(b, code.key...) + b = encodeBool(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagBoolOnly, opStructFieldHeadStringTagBoolOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + b = append(b, '"') + b = encodeBool(b, ptrToBool(p)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + case opStructFieldPtrHeadBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + break + } else { + b = append(b, '{') + b = append(b, code.key...) + p = ptrToPtr(p) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p+code.offset)) + } + } + b = encodeComma(b) + code = code.next + case opStructFieldPtrHeadOmitEmptyBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + p = ptrToPtr(p) + if p != 0 { + b = append(b, code.key...) + b = encodeBool(b, ptrToBool(p)) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + break + } else { + b = append(b, '{') + b = append(b, code.key...) + p = ptrToPtr(p) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeBool(b, ptrToBool(p+code.offset)) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next + case opStructFieldPtrHeadBoolPtrOnly: p := load(ctxptr, code.idx) if p == 0 { b = encodeNull(b) @@ -6458,24 +6610,18 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco } store(ctxptr, code.idx, ptrToPtr(p)) fallthrough - case opStructFieldHeadBool: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - if code.op == opStructFieldPtrHeadBool { - b = encodeNull(b) - b = encodeComma(b) - } else { - b = append(b, '{', '}', ',') - } - code = code.end.next + case opStructFieldHeadBoolPtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + if p == 0 { + b = encodeNull(b) } else { - b = append(b, '{') - b = append(b, code.key...) - b = encodeBool(b, ptrToBool(ptr+code.offset)) - b = encodeComma(b) - code = code.next + b = encodeBool(b, ptrToBool(p+code.offset)) } - case opStructFieldPtrHeadBoolOnly: + b = encodeComma(b) + code = code.next + case opStructFieldPtrHeadOmitEmptyBoolPtrOnly: p := load(ctxptr, code.idx) if p == 0 { b = encodeNull(b) @@ -6483,12 +6629,59 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco code = code.end.next break } + store(ctxptr, code.idx, ptrToPtr(p)) fallthrough - case opStructFieldHeadBoolOnly: - ptr := load(ctxptr, code.idx) + case opStructFieldHeadOmitEmptyBoolPtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.key...) + b = encodeBool(b, ptrToBool(p+code.offset)) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + break + } + store(ctxptr, code.idx, ptrToPtr(p)) + fallthrough + case opStructFieldHeadStringTagBoolPtrOnly: + p := load(ctxptr, code.idx) b = append(b, '{') b = append(b, code.key...) - b = encodeBool(b, ptrToBool(ptr+code.offset)) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeBool(b, ptrToBool(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldHeadBoolNPtr: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '{') + b = append(b, code.key...) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p+code.offset)) + } + } b = encodeComma(b) code = code.next case opStructFieldPtrAnonymousHeadBool: @@ -6504,6 +6697,194 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyBool: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyBool: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := ptrToBool(ptr + code.offset) + if v { + b = append(b, code.key...) + b = encodeBool(b, v) + b = encodeComma(b) + code = code.next + } else { + code = code.nextField + } + } + case opStructFieldPtrAnonymousHeadStringTagBool: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagBool: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.key...) + b = append(b, '"') + b = encodeBool(b, ptrToBool(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadBoolOnly, opStructFieldAnonymousHeadBoolOnly: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.key...) + b = encodeBool(b, ptrToBool(ptr+code.offset)) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadOmitEmptyBoolOnly, opStructFieldAnonymousHeadOmitEmptyBoolOnly: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := ptrToBool(ptr + code.offset) + if v { + b = append(b, code.key...) + b = encodeBool(b, v) + b = encodeComma(b) + code = code.next + } else { + code = code.nextField + } + } + case opStructFieldPtrAnonymousHeadStringTagBoolOnly, opStructFieldAnonymousHeadStringTagBoolOnly: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.key...) + b = append(b, '"') + b = encodeBool(b, ptrToBool(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + b = append(b, code.key...) + p = ptrToPtr(p) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p+code.offset)) + } + b = encodeComma(b) + code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + p = ptrToPtr(p) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = encodeBool(b, ptrToBool(p)) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + b = append(b, code.key...) + p = ptrToPtr(p) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeBool(b, ptrToBool(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldPtrAnonymousHeadBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadBoolPtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.key...) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p+code.offset)) + } + b = encodeComma(b) + code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = encodeBool(b, ptrToBool(p+code.offset)) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagBoolPtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.key...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeBool(b, ptrToBool(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadBytes: p := load(ctxptr, code.idx) if p == 0 { @@ -6770,51 +7151,6 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco b = encodeComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyBool: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyBool: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := ptrToBool(ptr + code.offset) - if !v { - code = code.nextField - } else { - b = append(b, code.key...) - b = encodeBool(b, v) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrAnonymousHeadOmitEmptyBool: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyBool: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := ptrToBool(ptr + code.offset) - if !v { - code = code.nextField - } else { - b = append(b, code.key...) - b = encodeBool(b, v) - b = encodeComma(b) - code = code.next - } - } case opStructFieldPtrHeadOmitEmptyBytes: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -7054,45 +7390,6 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco code = code.next store(ctxptr, code.idx, ptr+code.offset) } - case opStructFieldPtrHeadStringTagBool: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagBool: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - b = append(b, code.key...) - b = append(b, '"') - b = encodeBool(b, ptrToBool(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrAnonymousHeadStringTagBool: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagBool: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - b = append(b, code.key...) - b = append(b, '"') - b = encodeBool(b, ptrToBool(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagBytes: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -8111,7 +8408,9 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco if p == 0 { b = encodeNull(b) } else { + b = append(b, '"') b = encodeBool(b, ptrToBool(p)) + b = append(b, '"') } b = encodeComma(b) code = code.next @@ -9580,6 +9879,36 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco } b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyBoolPtr: + ptr := load(ctxptr, code.headIdx) + p := ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.key...) + b = encodeBool(b, ptrToBool(p)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } + } + code = code.next + case opStructEndStringTagBoolPtr: + b = append(b, code.key...) + ptr := load(ctxptr, code.headIdx) + p := ptrToPtr(ptr + code.offset) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeBool(b, ptrToBool(p)) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next case opStructEndBytes: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) diff --git a/encode_vm_escaped.go b/encode_vm_escaped.go index bbac701..1188b57 100644 --- a/encode_vm_escaped.go +++ b/encode_vm_escaped.go @@ -6387,6 +6387,158 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o b = encodeComma(b) code = code.next case opStructFieldPtrHeadBool: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadBool: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + b = append(b, code.escapedKey...) + b = encodeBool(b, ptrToBool(ptr+code.offset)) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrHeadOmitEmptyBool: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyBool: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := ptrToBool(ptr + code.offset) + if v { + b = append(b, code.escapedKey...) + b = encodeBool(b, v) + b = encodeComma(b) + code = code.next + } else { + code = code.nextField + } + } + case opStructFieldPtrHeadStringTagBool: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagBool: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + b = append(b, code.escapedKey...) + b = append(b, '"') + b = encodeBool(b, ptrToBool(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrHeadBoolOnly, opStructFieldHeadBoolOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.escapedKey...) + b = encodeBool(b, ptrToBool(p)) + b = encodeComma(b) + code = code.next + case opStructFieldPtrHeadOmitEmptyBoolOnly, opStructFieldHeadOmitEmptyBoolOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := ptrToBool(p) + if v { + b = append(b, code.escapedKey...) + b = encodeBool(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagBoolOnly, opStructFieldHeadStringTagBoolOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.escapedKey...) + b = append(b, '"') + b = encodeBool(b, ptrToBool(p)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + case opStructFieldPtrHeadBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + break + } else { + b = append(b, '{') + b = append(b, code.escapedKey...) + p = ptrToPtr(p) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p+code.offset)) + } + } + b = encodeComma(b) + code = code.next + case opStructFieldPtrHeadOmitEmptyBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + p = ptrToPtr(p) + if p != 0 { + b = append(b, code.escapedKey...) + b = encodeBool(b, ptrToBool(p)) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + break + } else { + b = append(b, '{') + b = append(b, code.escapedKey...) + p = ptrToPtr(p) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeBool(b, ptrToBool(p+code.offset)) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next + case opStructFieldPtrHeadBoolPtrOnly: p := load(ctxptr, code.idx) if p == 0 { b = encodeNull(b) @@ -6396,24 +6548,18 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o } store(ctxptr, code.idx, ptrToPtr(p)) fallthrough - case opStructFieldHeadBool: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - if code.op == opStructFieldPtrHeadBool { - b = encodeNull(b) - b = encodeComma(b) - } else { - b = append(b, '{', '}', ',') - } - code = code.end.next + case opStructFieldHeadBoolPtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.escapedKey...) + if p == 0 { + b = encodeNull(b) } else { - b = append(b, '{') - b = append(b, code.escapedKey...) - b = encodeBool(b, ptrToBool(ptr+code.offset)) - b = encodeComma(b) - code = code.next + b = encodeBool(b, ptrToBool(p+code.offset)) } - case opStructFieldPtrHeadBoolOnly: + b = encodeComma(b) + code = code.next + case opStructFieldPtrHeadOmitEmptyBoolPtrOnly: p := load(ctxptr, code.idx) if p == 0 { b = encodeNull(b) @@ -6421,12 +6567,59 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o code = code.end.next break } + store(ctxptr, code.idx, ptrToPtr(p)) fallthrough - case opStructFieldHeadBoolOnly: - ptr := load(ctxptr, code.idx) + case opStructFieldHeadOmitEmptyBoolPtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.escapedKey...) + b = encodeBool(b, ptrToBool(p+code.offset)) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + break + } + store(ctxptr, code.idx, ptrToPtr(p)) + fallthrough + case opStructFieldHeadStringTagBoolPtrOnly: + p := load(ctxptr, code.idx) b = append(b, '{') b = append(b, code.escapedKey...) - b = encodeBool(b, ptrToBool(ptr+code.offset)) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeBool(b, ptrToBool(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldHeadBoolNPtr: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '{') + b = append(b, code.escapedKey...) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p+code.offset)) + } + } b = encodeComma(b) code = code.next case opStructFieldPtrAnonymousHeadBool: @@ -6442,6 +6635,194 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyBool: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyBool: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := ptrToBool(ptr + code.offset) + if v { + b = append(b, code.escapedKey...) + b = encodeBool(b, v) + b = encodeComma(b) + code = code.next + } else { + code = code.nextField + } + } + case opStructFieldPtrAnonymousHeadStringTagBool: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagBool: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.escapedKey...) + b = append(b, '"') + b = encodeBool(b, ptrToBool(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadBoolOnly, opStructFieldAnonymousHeadBoolOnly: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.escapedKey...) + b = encodeBool(b, ptrToBool(ptr+code.offset)) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadOmitEmptyBoolOnly, opStructFieldAnonymousHeadOmitEmptyBoolOnly: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := ptrToBool(ptr + code.offset) + if v { + b = append(b, code.escapedKey...) + b = encodeBool(b, v) + b = encodeComma(b) + code = code.next + } else { + code = code.nextField + } + } + case opStructFieldPtrAnonymousHeadStringTagBoolOnly, opStructFieldAnonymousHeadStringTagBoolOnly: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.escapedKey...) + b = append(b, '"') + b = encodeBool(b, ptrToBool(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + b = append(b, code.escapedKey...) + p = ptrToPtr(p) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p+code.offset)) + } + b = encodeComma(b) + code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + p = ptrToPtr(p) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = encodeBool(b, ptrToBool(p)) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + b = append(b, code.escapedKey...) + p = ptrToPtr(p) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeBool(b, ptrToBool(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldPtrAnonymousHeadBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadBoolPtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.escapedKey...) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p+code.offset)) + } + b = encodeComma(b) + code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = encodeBool(b, ptrToBool(p+code.offset)) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagBoolPtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.escapedKey...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeBool(b, ptrToBool(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadBytes: p := load(ctxptr, code.idx) if p == 0 { @@ -6706,51 +7087,6 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o b = encodeComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyBool: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyBool: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := ptrToBool(ptr + code.offset) - if !v { - code = code.nextField - } else { - b = append(b, code.escapedKey...) - b = encodeBool(b, v) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrAnonymousHeadOmitEmptyBool: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyBool: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := ptrToBool(ptr + code.offset) - if !v { - code = code.nextField - } else { - b = append(b, code.escapedKey...) - b = encodeBool(b, v) - b = encodeComma(b) - code = code.next - } - } case opStructFieldPtrHeadOmitEmptyBytes: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -6988,63 +7324,6 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o code = code.next store(ctxptr, code.idx, ptr+code.offset) } - case opStructFieldPtrHeadStringTagBool: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagBool: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - b = append(b, code.escapedKey...) - b = append(b, '"') - b = encodeBool(b, ptrToBool(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrHeadStringTagBoolOnly: - p := load(ctxptr, code.idx) - if p == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - break - } - fallthrough - case opStructFieldHeadStringTagBoolOnly: - ptr := load(ctxptr, code.idx) - b = append(b, '{') - b = append(b, code.escapedKey...) - b = append(b, '"') - b = encodeBool(b, ptrToBool(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldPtrAnonymousHeadStringTagBool: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagBool: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - b = append(b, code.escapedKey...) - b = append(b, '"') - b = encodeBool(b, ptrToBool(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagBytes: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -8063,7 +8342,9 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o if p == 0 { b = encodeNull(b) } else { + b = append(b, '"') b = encodeBool(b, ptrToBool(p)) + b = append(b, '"') } b = encodeComma(b) code = code.next @@ -9541,6 +9822,36 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o } b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyBoolPtr: + ptr := load(ctxptr, code.headIdx) + p := ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.escapedKey...) + b = encodeBool(b, ptrToBool(p)) + b = appendStructEnd(b) + } else { + last := len(b) - 1 + if b[last] == ',' { + b[last] = '}' + b = encodeComma(b) + } else { + b = appendStructEnd(b) + } + } + code = code.next + case opStructEndStringTagBoolPtr: + b = append(b, code.escapedKey...) + ptr := load(ctxptr, code.headIdx) + p := ptrToPtr(ptr + code.offset) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeBool(b, ptrToBool(p)) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next case opStructEndBytes: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) diff --git a/encode_vm_escaped_indent.go b/encode_vm_escaped_indent.go index 8674b46..472b3c1 100644 --- a/encode_vm_escaped_indent.go +++ b/encode_vm_escaped_indent.go @@ -6962,12 +6962,10 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode case opStructFieldHeadBool: ptr := load(ctxptr, code.idx) if ptr == 0 { - b = appendIndent(ctx, b, code.indent) b = encodeNull(b) b = encodeIndentComma(b) code = code.end.next } else { - b = appendIndent(ctx, b, code.indent) b = append(b, '{', '\n') b = appendIndent(ctx, b, code.indent+1) b = append(b, code.escapedKey...) @@ -6976,6 +6974,467 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyBool: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyBool: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeIndentComma(b) + code = code.end.next + } else { + b = append(b, '{', '\n') + v := ptrToBool(ptr + code.offset) + if v { + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeBool(b, v) + b = encodeIndentComma(b) + code = code.next + } else { + code = code.nextField + } + } + case opStructFieldPtrHeadStringTagBool: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagBool: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeIndentComma(b) + code = code.end.next + } else { + b = append(b, '{', '\n') + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = encodeBool(b, ptrToBool(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrHeadBoolOnly, opStructFieldHeadBoolOnly: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeBool(b, ptrToBool(p)) + b = encodeIndentComma(b) + code = code.next + case opStructFieldPtrHeadOmitEmptyBoolOnly, opStructFieldHeadOmitEmptyBoolOnly: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := ptrToBool(p) + if v { + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeBool(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagBoolOnly, opStructFieldHeadStringTagBoolOnly: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = encodeBool(b, ptrToBool(p)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + case opStructFieldPtrHeadBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeIndentComma(b) + code = code.end.next + break + } else { + b = append(b, '{', '\n') + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.escapedKey...) + b = append(b, ' ') + p = ptrToPtr(p) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p+code.offset)) + } + } + b = encodeIndentComma(b) + code = code.next + case opStructFieldPtrHeadOmitEmptyBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeIndentComma(b) + code = code.end.next + } else { + b = append(b, '{', '\n') + p = ptrToPtr(p) + if p != 0 { + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeBool(b, ptrToBool(p)) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeIndentComma(b) + code = code.end.next + break + } else { + b = append(b, '{', '\n') + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.escapedKey...) + b = append(b, ' ') + p = ptrToPtr(p) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeBool(b, ptrToBool(p+code.offset)) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next + case opStructFieldPtrHeadBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeIndentComma(b) + code = code.end.next + break + } + store(ctxptr, code.idx, ptrToPtr(p)) + fallthrough + case opStructFieldHeadBoolPtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.escapedKey...) + b = append(b, ' ') + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p+code.offset)) + } + b = encodeIndentComma(b) + code = code.next + case opStructFieldPtrHeadOmitEmptyBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeIndentComma(b) + code = code.end.next + break + } + store(ctxptr, code.idx, ptrToPtr(p)) + fallthrough + case opStructFieldHeadOmitEmptyBoolPtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + if p != 0 { + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeBool(b, ptrToBool(p+code.offset)) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeIndentComma(b) + code = code.end.next + break + } + store(ctxptr, code.idx, ptrToPtr(p)) + fallthrough + case opStructFieldHeadStringTagBoolPtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.escapedKey...) + b = append(b, ' ') + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeBool(b, ptrToBool(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next + case opStructFieldHeadBoolNPtr: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '{', '\n') + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.escapedKey...) + b = append(b, ' ') + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p+code.offset)) + } + } + b = encodeIndentComma(b) + code = code.next + case opStructFieldPtrAnonymousHeadBool: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadBool: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = appendIndent(ctx, b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeBool(b, ptrToBool(ptr+code.offset)) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadOmitEmptyBool: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyBool: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := ptrToBool(ptr + code.offset) + if v { + b = appendIndent(ctx, b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeBool(b, v) + b = encodeIndentComma(b) + code = code.next + } else { + code = code.nextField + } + } + case opStructFieldPtrAnonymousHeadStringTagBool: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagBool: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = appendIndent(ctx, b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = append(b, '"') + b = encodeBool(b, ptrToBool(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadBoolOnly, opStructFieldAnonymousHeadBoolOnly: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = appendIndent(ctx, b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeBool(b, ptrToBool(ptr+code.offset)) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadOmitEmptyBoolOnly, opStructFieldAnonymousHeadOmitEmptyBoolOnly: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := ptrToBool(ptr + code.offset) + if v { + b = appendIndent(ctx, b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeBool(b, v) + b = encodeIndentComma(b) + code = code.next + } else { + code = code.nextField + } + } + case opStructFieldPtrAnonymousHeadStringTagBoolOnly, opStructFieldAnonymousHeadStringTagBoolOnly: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = appendIndent(ctx, b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = append(b, '"') + b = encodeBool(b, ptrToBool(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + b = appendIndent(ctx, b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + p = ptrToPtr(p) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p+code.offset)) + } + b = encodeIndentComma(b) + code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + p = ptrToPtr(p) + if p == 0 { + code = code.nextField + } else { + b = appendIndent(ctx, b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeBool(b, ptrToBool(p)) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + b = appendIndent(ctx, b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + p = ptrToPtr(p) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeBool(b, ptrToBool(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next + case opStructFieldPtrAnonymousHeadBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadBoolPtrOnly: + p := load(ctxptr, code.idx) + b = appendIndent(ctx, b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p+code.offset)) + } + b = encodeIndentComma(b) + code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = appendIndent(ctx, b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeBool(b, ptrToBool(p+code.offset)) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagBoolPtrOnly: + p := load(ctxptr, code.idx) + b = appendIndent(ctx, b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeBool(b, ptrToBool(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadBytes: store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -6996,34 +7455,6 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = encodeIndentComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyBool: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyBool: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = appendIndent(ctx, b, code.indent) - b = encodeNull(b) - b = encodeIndentComma(b) - code = code.end.next - } else { - b = appendIndent(ctx, b, code.indent) - b = append(b, '{', '\n') - v := ptrToBool(ptr + code.offset) - if !v { - code = code.nextField - } else { - b = appendIndent(ctx, b, code.indent+1) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = encodeBool(b, v) - b = encodeIndentComma(b) - code = code.next - } - } case opStructFieldPtrHeadOmitEmptyBytes: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -7073,29 +7504,6 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode code = code.next store(ctxptr, code.idx, p) } - case opStructFieldPtrHeadStringTagBool: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagBool: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = appendIndent(ctx, b, code.indent) - b = encodeNull(b) - b = encodeIndentComma(b) - code = code.end.next - } else { - b = append(b, '{', '\n') - b = appendIndent(ctx, b, code.indent+1) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = encodeBool(b, ptrToBool(ptr+code.offset)) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagBytes: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -8099,7 +8507,9 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode if p == 0 { b = encodeNull(b) } else { + b = append(b, '"') b = encodeBool(b, ptrToBool(p)) + b = append(b, '"') } b = encodeIndentComma(b) code = code.next @@ -8444,7 +8854,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -8491,7 +8901,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -8539,7 +8949,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -8586,7 +8996,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -8634,7 +9044,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -8681,7 +9091,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -8729,7 +9139,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -8776,7 +9186,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -8824,7 +9234,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -8871,7 +9281,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -8919,7 +9329,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -8966,7 +9376,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9014,7 +9424,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9061,7 +9471,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9109,7 +9519,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9156,7 +9566,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9204,7 +9614,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9251,7 +9661,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9299,7 +9709,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9346,7 +9756,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9394,7 +9804,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9441,7 +9851,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9496,7 +9906,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9555,7 +9965,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9607,7 +10017,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9654,7 +10064,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9700,7 +10110,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9715,6 +10125,59 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = append(b, '"') b = appendStructEndIndent(ctx, b, code.indent-1) code = code.next + case opStructEndBoolPtr: + b = appendIndent(ctx, b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + ptr := load(ctxptr, code.headIdx) + p := ptrToPtr(ptr + code.offset) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p)) + } + b = appendStructEndIndent(ctx, b, code.indent-1) + code = code.next + case opStructEndOmitEmptyBoolPtr: + ptr := load(ctxptr, code.headIdx) + p := ptrToPtr(ptr + code.offset) + if p != 0 { + b = appendIndent(ctx, b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeBool(b, ptrToBool(p)) + b = appendStructEndIndent(ctx, b, code.indent-1) + } else { + last := len(b) - 1 + if b[last-1] == '{' { + b[last] = '}' + } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = appendIndent(ctx, b, code.indent-1) + b = append(b, '}') + } + b = encodeIndentComma(b) + } + code = code.next + case opStructEndStringTagBoolPtr: + b = appendIndent(ctx, b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + ptr := load(ctxptr, code.headIdx) + p := ptrToPtr(ptr + code.offset) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeBool(b, ptrToBool(p)) + b = append(b, '"') + } + b = appendStructEndIndent(ctx, b, code.indent-1) + code = code.next case opStructEndBytes: b = appendIndent(ctx, b, code.indent) b = append(b, code.escapedKey...) @@ -9742,7 +10205,7 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) diff --git a/encode_vm_indent.go b/encode_vm_indent.go index 231060e..a88918d 100644 --- a/encode_vm_indent.go +++ b/encode_vm_indent.go @@ -6962,12 +6962,10 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op case opStructFieldHeadBool: ptr := load(ctxptr, code.idx) if ptr == 0 { - b = appendIndent(ctx, b, code.indent) b = encodeNull(b) b = encodeIndentComma(b) code = code.end.next } else { - b = appendIndent(ctx, b, code.indent) b = append(b, '{', '\n') b = appendIndent(ctx, b, code.indent+1) b = append(b, code.key...) @@ -6976,6 +6974,467 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyBool: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyBool: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeIndentComma(b) + code = code.end.next + } else { + b = append(b, '{', '\n') + v := ptrToBool(ptr + code.offset) + if v { + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeBool(b, v) + b = encodeIndentComma(b) + code = code.next + } else { + code = code.nextField + } + } + case opStructFieldPtrHeadStringTagBool: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagBool: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeIndentComma(b) + code = code.end.next + } else { + b = append(b, '{', '\n') + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = encodeBool(b, ptrToBool(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrHeadBoolOnly, opStructFieldHeadBoolOnly: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeBool(b, ptrToBool(p)) + b = encodeIndentComma(b) + code = code.next + case opStructFieldPtrHeadOmitEmptyBoolOnly, opStructFieldHeadOmitEmptyBoolOnly: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := ptrToBool(p) + if v { + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeBool(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagBoolOnly, opStructFieldHeadStringTagBoolOnly: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = encodeBool(b, ptrToBool(p)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + case opStructFieldPtrHeadBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeIndentComma(b) + code = code.end.next + break + } else { + b = append(b, '{', '\n') + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.key...) + b = append(b, ' ') + p = ptrToPtr(p) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p+code.offset)) + } + } + b = encodeIndentComma(b) + code = code.next + case opStructFieldPtrHeadOmitEmptyBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeIndentComma(b) + code = code.end.next + } else { + b = append(b, '{', '\n') + p = ptrToPtr(p) + if p != 0 { + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeBool(b, ptrToBool(p)) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeIndentComma(b) + code = code.end.next + break + } else { + b = append(b, '{', '\n') + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.key...) + b = append(b, ' ') + p = ptrToPtr(p) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeBool(b, ptrToBool(p+code.offset)) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next + case opStructFieldPtrHeadBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeIndentComma(b) + code = code.end.next + break + } + store(ctxptr, code.idx, ptrToPtr(p)) + fallthrough + case opStructFieldHeadBoolPtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.key...) + b = append(b, ' ') + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p+code.offset)) + } + b = encodeIndentComma(b) + code = code.next + case opStructFieldPtrHeadOmitEmptyBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeIndentComma(b) + code = code.end.next + break + } + store(ctxptr, code.idx, ptrToPtr(p)) + fallthrough + case opStructFieldHeadOmitEmptyBoolPtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + if p != 0 { + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeBool(b, ptrToBool(p+code.offset)) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + b = encodeIndentComma(b) + code = code.end.next + break + } + store(ctxptr, code.idx, ptrToPtr(p)) + fallthrough + case opStructFieldHeadStringTagBoolPtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.key...) + b = append(b, ' ') + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeBool(b, ptrToBool(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next + case opStructFieldHeadBoolNPtr: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '{', '\n') + b = appendIndent(ctx, b, code.indent+1) + b = append(b, code.key...) + b = append(b, ' ') + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p+code.offset)) + } + } + b = encodeIndentComma(b) + code = code.next + case opStructFieldPtrAnonymousHeadBool: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadBool: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = appendIndent(ctx, b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeBool(b, ptrToBool(ptr+code.offset)) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadOmitEmptyBool: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyBool: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := ptrToBool(ptr + code.offset) + if v { + b = appendIndent(ctx, b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeBool(b, v) + b = encodeIndentComma(b) + code = code.next + } else { + code = code.nextField + } + } + case opStructFieldPtrAnonymousHeadStringTagBool: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagBool: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = appendIndent(ctx, b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = append(b, '"') + b = encodeBool(b, ptrToBool(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadBoolOnly, opStructFieldAnonymousHeadBoolOnly: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = appendIndent(ctx, b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeBool(b, ptrToBool(ptr+code.offset)) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadOmitEmptyBoolOnly, opStructFieldAnonymousHeadOmitEmptyBoolOnly: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := ptrToBool(ptr + code.offset) + if v { + b = appendIndent(ctx, b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeBool(b, v) + b = encodeIndentComma(b) + code = code.next + } else { + code = code.nextField + } + } + case opStructFieldPtrAnonymousHeadStringTagBoolOnly, opStructFieldAnonymousHeadStringTagBoolOnly: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = appendIndent(ctx, b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = append(b, '"') + b = encodeBool(b, ptrToBool(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + b = appendIndent(ctx, b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + p = ptrToPtr(p) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p+code.offset)) + } + b = encodeIndentComma(b) + code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + p = ptrToPtr(p) + if p == 0 { + code = code.nextField + } else { + b = appendIndent(ctx, b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeBool(b, ptrToBool(p)) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagBoolPtr: + store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagBoolPtr: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + b = appendIndent(ctx, b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + p = ptrToPtr(p) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeBool(b, ptrToBool(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next + case opStructFieldPtrAnonymousHeadBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadBoolPtrOnly: + p := load(ctxptr, code.idx) + b = appendIndent(ctx, b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p+code.offset)) + } + b = encodeIndentComma(b) + code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = appendIndent(ctx, b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeBool(b, ptrToBool(p+code.offset)) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagBoolPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagBoolPtrOnly: + p := load(ctxptr, code.idx) + b = appendIndent(ctx, b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeBool(b, ptrToBool(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadBytes: store(ctxptr, code.idx, ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -6996,34 +7455,6 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = encodeIndentComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyBool: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyBool: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = appendIndent(ctx, b, code.indent) - b = encodeNull(b) - b = encodeIndentComma(b) - code = code.end.next - } else { - b = appendIndent(ctx, b, code.indent) - b = append(b, '{', '\n') - v := ptrToBool(ptr + code.offset) - if !v { - code = code.nextField - } else { - b = appendIndent(ctx, b, code.indent+1) - b = append(b, code.key...) - b = append(b, ' ') - b = encodeBool(b, v) - b = encodeIndentComma(b) - code = code.next - } - } case opStructFieldPtrHeadOmitEmptyBytes: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -7073,29 +7504,6 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op code = code.next store(ctxptr, code.idx, p) } - case opStructFieldPtrHeadStringTagBool: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagBool: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = appendIndent(ctx, b, code.indent) - b = encodeNull(b) - b = encodeIndentComma(b) - code = code.end.next - } else { - b = append(b, '{', '\n') - b = appendIndent(ctx, b, code.indent+1) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = encodeBool(b, ptrToBool(ptr+code.offset)) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagBytes: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -8099,7 +8507,9 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op if p == 0 { b = encodeNull(b) } else { + b = append(b, '"') b = encodeBool(b, ptrToBool(p)) + b = append(b, '"') } b = encodeIndentComma(b) code = code.next @@ -8443,7 +8853,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -8490,7 +8900,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -8538,7 +8948,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -8585,7 +8995,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -8633,7 +9043,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -8680,7 +9090,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -8728,7 +9138,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -8775,7 +9185,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -8823,7 +9233,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -8870,7 +9280,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -8918,7 +9328,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -8965,7 +9375,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9013,7 +9423,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9060,7 +9470,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9108,7 +9518,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9155,7 +9565,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9203,7 +9613,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9250,7 +9660,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9298,7 +9708,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9345,7 +9755,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9393,7 +9803,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9440,7 +9850,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9495,7 +9905,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9554,7 +9964,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9606,7 +10016,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9653,7 +10063,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9699,7 +10109,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b) @@ -9714,6 +10124,59 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = append(b, '"') b = appendStructEndIndent(ctx, b, code.indent-1) code = code.next + case opStructEndBoolPtr: + b = appendIndent(ctx, b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + ptr := load(ctxptr, code.headIdx) + p := ptrToPtr(ptr + code.offset) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p)) + } + b = appendStructEndIndent(ctx, b, code.indent-1) + code = code.next + case opStructEndOmitEmptyBoolPtr: + ptr := load(ctxptr, code.headIdx) + p := ptrToPtr(ptr + code.offset) + if p != 0 { + b = appendIndent(ctx, b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeBool(b, ptrToBool(p)) + b = appendStructEndIndent(ctx, b, code.indent-1) + } else { + last := len(b) - 1 + if b[last-1] == '{' { + b[last] = '}' + } else { + if b[last] == '\n' { + // to remove ',' and '\n' characters + b = b[:len(b)-2] + } + b = append(b, '\n') + b = appendIndent(ctx, b, code.indent-1) + b = append(b, '}') + } + b = encodeIndentComma(b) + } + code = code.next + case opStructEndStringTagBoolPtr: + b = appendIndent(ctx, b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + ptr := load(ctxptr, code.headIdx) + p := ptrToPtr(ptr + code.offset) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeBool(b, ptrToBool(p)) + b = append(b, '"') + } + b = appendStructEndIndent(ctx, b, code.indent-1) + code = code.next case opStructEndBytes: b = appendIndent(ctx, b, code.indent) b = append(b, code.key...) @@ -9741,7 +10204,7 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = b[:len(b)-2] } b = append(b, '\n') - b = appendIndent(ctx, b, code.indent) + b = appendIndent(ctx, b, code.indent-1) b = append(b, '}') } b = encodeIndentComma(b)