Add StructFieldOmitEmptyStringPtr

This commit is contained in:
Masaaki Goshima 2021-01-22 18:19:54 +09:00
parent d933310ad4
commit d59cdefc1d
5 changed files with 336 additions and 1349 deletions

File diff suppressed because it is too large Load Diff

View File

@ -7759,6 +7759,26 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
} }
b = encodeComma(b) b = encodeComma(b)
code = code.next code = code.next
case opStructFieldOmitEmptyStringPtr:
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p != 0 {
b = append(b, code.key...)
b = encodeNoEscapedString(b, e.ptrToString(p))
b = encodeComma(b)
}
code = code.next
case opStructFieldStringTagStringPtr:
b = append(b, code.key...)
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
} else {
b = encodeNoEscapedString(b, string(encodeNoEscapedString([]byte{}, e.ptrToString(p))))
}
b = encodeComma(b)
code = code.next
case opStructFieldBool: case opStructFieldBool:
ptr := load(ctxptr, code.headIdx) ptr := load(ctxptr, code.headIdx)
b = append(b, code.key...) b = append(b, code.key...)

View File

@ -7745,6 +7745,26 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
} }
b = encodeComma(b) b = encodeComma(b)
code = code.next code = code.next
case opStructFieldOmitEmptyStringPtr:
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p != 0 {
b = append(b, code.escapedKey...)
b = encodeNoEscapedString(b, e.ptrToString(p))
b = encodeComma(b)
}
code = code.next
case opStructFieldStringTagStringPtr:
b = append(b, code.escapedKey...)
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
} else {
b = encodeEscapedString(b, string(encodeEscapedString([]byte{}, e.ptrToString(p))))
}
b = encodeComma(b)
code = code.next
case opStructFieldBool: case opStructFieldBool:
ptr := load(ctxptr, code.headIdx) ptr := load(ctxptr, code.headIdx)
b = append(b, code.escapedKey...) b = append(b, code.escapedKey...)

View File

@ -7552,6 +7552,43 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
b = encodeEscapedString(b, string(encodeEscapedString([]byte{}, s))) b = encodeEscapedString(b, string(encodeEscapedString([]byte{}, s)))
b = encodeIndentComma(b) b = encodeIndentComma(b)
code = code.next code = code.next
case opStructFieldStringPtr:
b = e.encodeIndent(b, code.indent)
b = append(b, code.escapedKey...)
b = append(b, ' ')
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
} else {
b = encodeEscapedString(b, e.ptrToString(p))
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldOmitEmptyStringPtr:
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p != 0 {
b = e.encodeIndent(b, code.indent)
b = append(b, code.escapedKey...)
b = append(b, ' ')
b = encodeNoEscapedString(b, e.ptrToString(p))
b = encodeIndentComma(b)
}
code = code.next
case opStructFieldStringTagStringPtr:
b = e.encodeIndent(b, code.indent)
b = append(b, code.escapedKey...)
b = append(b, ' ')
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
} else {
b = encodeEscapedString(b, string(encodeEscapedString([]byte{}, e.ptrToString(p))))
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldBool: case opStructFieldBool:
b = e.encodeIndent(b, code.indent) b = e.encodeIndent(b, code.indent)
b = append(b, code.escapedKey...) b = append(b, code.escapedKey...)

View File

@ -7552,6 +7552,43 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
b = encodeNoEscapedString(b, string(encodeNoEscapedString([]byte{}, s))) b = encodeNoEscapedString(b, string(encodeNoEscapedString([]byte{}, s)))
b = encodeIndentComma(b) b = encodeIndentComma(b)
code = code.next code = code.next
case opStructFieldStringPtr:
b = e.encodeIndent(b, code.indent)
b = append(b, code.key...)
b = append(b, ' ')
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
} else {
b = encodeNoEscapedString(b, e.ptrToString(p))
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldOmitEmptyStringPtr:
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p != 0 {
b = e.encodeIndent(b, code.indent)
b = append(b, code.key...)
b = append(b, ' ')
b = encodeNoEscapedString(b, e.ptrToString(p))
b = encodeIndentComma(b)
}
code = code.next
case opStructFieldStringTagStringPtr:
b = e.encodeIndent(b, code.indent)
b = append(b, code.key...)
b = append(b, ' ')
ptr := load(ctxptr, code.headIdx)
p := e.ptrToPtr(ptr + code.offset)
if p == 0 {
b = encodeNull(b)
} else {
b = encodeNoEscapedString(b, string(encodeNoEscapedString([]byte{}, e.ptrToString(p))))
}
b = encodeIndentComma(b)
code = code.next
case opStructFieldBool: case opStructFieldBool:
b = e.encodeIndent(b, code.indent) b = e.encodeIndent(b, code.indent)
b = append(b, code.key...) b = append(b, code.key...)