Enable StructEnd optimization for ptr type

This commit is contained in:
Masaaki Goshima 2021-11-28 12:35:20 +09:00
parent ea19d1161a
commit be85245267
No known key found for this signature in database
GPG Key ID: 6A53785055537153
1 changed files with 5 additions and 3 deletions

View File

@ -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
} }