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)
if isEndField {
if isEnableStructEndOptimizationType(c.value.Kind()) {
if isEnableStructEndOptimization(c.value) {
field.Op = field.Op.FieldToEnd()
} else {
codes = c.addStructEndCode(ctx, codes)
@ -708,8 +708,8 @@ func (c *StructFieldCode) ToAnonymousOpcode(ctx *compileContext, isFirstField, i
return c.fieldOpcodes(ctx, field, valueCodes)
}
func isEnableStructEndOptimizationType(typ CodeKind) bool {
switch typ {
func isEnableStructEndOptimization(value Code) bool {
switch value.Kind() {
case CodeKindInt,
CodeKindUint,
CodeKindFloat,
@ -717,6 +717,8 @@ func isEnableStructEndOptimizationType(typ CodeKind) bool {
CodeKindBool,
CodeKindBytes:
return true
case CodeKindPtr:
return isEnableStructEndOptimization(value.(*PtrCode).value)
default:
return false
}