refactor: to check for IsDirectedNil only if ifacePtr == nil

This commit is contained in:
Nao Yonashiro 2022-07-03 22:39:31 +09:00
parent c8d6da88dd
commit 884b8dbf9a
5 changed files with 35 additions and 25 deletions

View File

@ -194,11 +194,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
ifacePtr = iface.ptr ifacePtr = iface.ptr
typ = iface.typ typ = iface.typ
} }
isDirectedNil := typ != nil && typ.Kind() == reflect.Struct && !runtime.IfaceIndir(typ) if ifacePtr == nil {
if ifacePtr == nil && !isDirectedNil { isDirectedNil := typ != nil && typ.Kind() == reflect.Struct && !runtime.IfaceIndir(typ)
b = appendNullComma(ctx, b) if !isDirectedNil {
code = code.Next b = appendNullComma(ctx, b)
break code = code.Next
break
}
} }
ctx.KeepRefs = append(ctx.KeepRefs, up) ctx.KeepRefs = append(ctx.KeepRefs, up)
ifaceCodeSet, err := encoder.CompileToGetCodeSet(ctx, uintptr(unsafe.Pointer(typ))) ifaceCodeSet, err := encoder.CompileToGetCodeSet(ctx, uintptr(unsafe.Pointer(typ)))

View File

@ -194,11 +194,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
ifacePtr = iface.ptr ifacePtr = iface.ptr
typ = iface.typ typ = iface.typ
} }
isDirectedNil := typ != nil && typ.Kind() == reflect.Struct && !runtime.IfaceIndir(typ) if ifacePtr == nil {
if ifacePtr == nil && !isDirectedNil { isDirectedNil := typ != nil && typ.Kind() == reflect.Struct && !runtime.IfaceIndir(typ)
b = appendNullComma(ctx, b) if !isDirectedNil {
code = code.Next b = appendNullComma(ctx, b)
break code = code.Next
break
}
} }
ctx.KeepRefs = append(ctx.KeepRefs, up) ctx.KeepRefs = append(ctx.KeepRefs, up)
ifaceCodeSet, err := encoder.CompileToGetCodeSet(ctx, uintptr(unsafe.Pointer(typ))) ifaceCodeSet, err := encoder.CompileToGetCodeSet(ctx, uintptr(unsafe.Pointer(typ)))

View File

@ -194,11 +194,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
ifacePtr = iface.ptr ifacePtr = iface.ptr
typ = iface.typ typ = iface.typ
} }
isDirectedNil := typ != nil && typ.Kind() == reflect.Struct && !runtime.IfaceIndir(typ) if ifacePtr == nil {
if ifacePtr == nil && !isDirectedNil { isDirectedNil := typ != nil && typ.Kind() == reflect.Struct && !runtime.IfaceIndir(typ)
b = appendNullComma(ctx, b) if !isDirectedNil {
code = code.Next b = appendNullComma(ctx, b)
break code = code.Next
break
}
} }
ctx.KeepRefs = append(ctx.KeepRefs, up) ctx.KeepRefs = append(ctx.KeepRefs, up)
ifaceCodeSet, err := encoder.CompileToGetCodeSet(ctx, uintptr(unsafe.Pointer(typ))) ifaceCodeSet, err := encoder.CompileToGetCodeSet(ctx, uintptr(unsafe.Pointer(typ)))

View File

@ -194,11 +194,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
ifacePtr = iface.ptr ifacePtr = iface.ptr
typ = iface.typ typ = iface.typ
} }
isDirectedNil := typ != nil && typ.Kind() == reflect.Struct && !runtime.IfaceIndir(typ) if ifacePtr == nil {
if ifacePtr == nil && !isDirectedNil { isDirectedNil := typ != nil && typ.Kind() == reflect.Struct && !runtime.IfaceIndir(typ)
b = appendNullComma(ctx, b) if !isDirectedNil {
code = code.Next b = appendNullComma(ctx, b)
break code = code.Next
break
}
} }
ctx.KeepRefs = append(ctx.KeepRefs, up) ctx.KeepRefs = append(ctx.KeepRefs, up)
ifaceCodeSet, err := encoder.CompileToGetCodeSet(ctx, uintptr(unsafe.Pointer(typ))) ifaceCodeSet, err := encoder.CompileToGetCodeSet(ctx, uintptr(unsafe.Pointer(typ)))

View File

@ -194,11 +194,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
ifacePtr = iface.ptr ifacePtr = iface.ptr
typ = iface.typ typ = iface.typ
} }
isDirectedNil := typ != nil && typ.Kind() == reflect.Struct && !runtime.IfaceIndir(typ) if ifacePtr == nil {
if ifacePtr == nil && !isDirectedNil { isDirectedNil := typ != nil && typ.Kind() == reflect.Struct && !runtime.IfaceIndir(typ)
b = appendNullComma(ctx, b) if !isDirectedNil {
code = code.Next b = appendNullComma(ctx, b)
break code = code.Next
break
}
} }
ctx.KeepRefs = append(ctx.KeepRefs, up) ctx.KeepRefs = append(ctx.KeepRefs, up)
ifaceCodeSet, err := encoder.CompileToGetCodeSet(ctx, uintptr(unsafe.Pointer(typ))) ifaceCodeSet, err := encoder.CompileToGetCodeSet(ctx, uintptr(unsafe.Pointer(typ)))