Refactor encoding of structHead and structKey

This commit is contained in:
Masaaki Goshima 2021-05-17 18:58:59 +09:00
parent 102554cbcd
commit 6ae63e3e61
11 changed files with 1674 additions and 2421 deletions

View File

@ -1050,7 +1050,6 @@ func compiledCode(ctx *compileContext) *Opcode {
} }
func structHeader(ctx *compileContext, fieldCode *Opcode, valueCode *Opcode, tag *runtime.StructTag) *Opcode { func structHeader(ctx *compileContext, fieldCode *Opcode, valueCode *Opcode, tag *runtime.StructTag) *Opcode {
fieldCode.Indent--
op := optimizeStructHeader(valueCode, tag) op := optimizeStructHeader(valueCode, tag)
fieldCode.Op = op fieldCode.Op = op
fieldCode.Mask = valueCode.Mask fieldCode.Mask = valueCode.Mask

View File

@ -76,6 +76,14 @@ func appendComma(b []byte) []byte {
return append(b, ',') 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 { func appendStructEnd(b []byte) []byte {
return append(b, '}', ',') return append(b, '}', ',')
} }

File diff suppressed because it is too large Load Diff

View File

@ -76,6 +76,14 @@ func appendComma(b []byte) []byte {
return append(b, ',') 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 { func appendStructEnd(b []byte) []byte {
return append(b, '}', ',') return append(b, '}', ',')
} }

File diff suppressed because it is too large Load Diff

View File

@ -76,6 +76,14 @@ func appendComma(b []byte) []byte {
return append(b, ',') 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 { func appendStructEnd(b []byte) []byte {
return append(b, '}', ',') return append(b, '}', ',')
} }

File diff suppressed because it is too large Load Diff

View File

@ -76,6 +76,16 @@ func appendComma(b []byte) []byte {
return append(b, ',', '\n') 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 { func appendStructEndSkipLast(ctx *encoder.RuntimeContext, b []byte, code *encoder.Opcode) []byte {
last := len(b) - 1 last := len(b) - 1
if b[last-1] == '{' { if b[last-1] == '{' {

File diff suppressed because it is too large Load Diff

View File

@ -76,6 +76,16 @@ func appendComma(b []byte) []byte {
return append(b, ',', '\n') 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 { func appendStructEndSkipLast(ctx *encoder.RuntimeContext, b []byte, code *encoder.Opcode) []byte {
last := len(b) - 1 last := len(b) - 1
if b[last-1] == '{' { if b[last-1] == '{' {

File diff suppressed because it is too large Load Diff