forked from mirror/go-json
Enable StructEnd optimization for ptr type
This commit is contained in:
parent
ea19d1161a
commit
be85245267
|
@ -680,7 +680,7 @@ func (c *StructFieldCode) ToOpcode(ctx *compileContext, isFirstField, isEndField
|
||||||
}
|
}
|
||||||
codes := c.fieldOpcodes(ctx, field, valueCodes)
|
codes := c.fieldOpcodes(ctx, field, valueCodes)
|
||||||
if isEndField {
|
if isEndField {
|
||||||
if isEnableStructEndOptimizationType(c.value.Kind()) {
|
if isEnableStructEndOptimization(c.value) {
|
||||||
field.Op = field.Op.FieldToEnd()
|
field.Op = field.Op.FieldToEnd()
|
||||||
} else {
|
} else {
|
||||||
codes = c.addStructEndCode(ctx, codes)
|
codes = c.addStructEndCode(ctx, codes)
|
||||||
|
@ -708,8 +708,8 @@ func (c *StructFieldCode) ToAnonymousOpcode(ctx *compileContext, isFirstField, i
|
||||||
return c.fieldOpcodes(ctx, field, valueCodes)
|
return c.fieldOpcodes(ctx, field, valueCodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isEnableStructEndOptimizationType(typ CodeKind) bool {
|
func isEnableStructEndOptimization(value Code) bool {
|
||||||
switch typ {
|
switch value.Kind() {
|
||||||
case CodeKindInt,
|
case CodeKindInt,
|
||||||
CodeKindUint,
|
CodeKindUint,
|
||||||
CodeKindFloat,
|
CodeKindFloat,
|
||||||
|
@ -717,6 +717,8 @@ func isEnableStructEndOptimizationType(typ CodeKind) bool {
|
||||||
CodeKindBool,
|
CodeKindBool,
|
||||||
CodeKindBytes:
|
CodeKindBytes:
|
||||||
return true
|
return true
|
||||||
|
case CodeKindPtr:
|
||||||
|
return isEnableStructEndOptimization(value.(*PtrCode).value)
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue