diff --git a/src/reflect/value.go b/src/reflect/value.go index 1fadd01298..68b97e9229 100644 --- a/src/reflect/value.go +++ b/src/reflect/value.go @@ -121,8 +121,8 @@ func (v Value) pointer() unsafe.Pointer { // packEface converts v to the empty interface. func packEface(v Value) any { t := v.typ() - var i any - e := (*abi.EmptyInterface)(unsafe.Pointer(&i)) + // Declare e as a struct (and not pointer to struct) to help escape analysis. + e := abi.EmptyInterface{} // First, fill in the data portion of the interface. switch { case t.IfaceIndir(): @@ -145,12 +145,9 @@ func packEface(v Value) any { // Value is direct, and so is the interface. e.Data = v.ptr } - // Now, fill in the type portion. We're very careful here not - // to have any operation between the e.word and e.typ assignments - // that would let the garbage collector observe the partially-built - // interface value. + // Now, fill in the type portion. e.Type = t - return i + return *(*any)(unsafe.Pointer(&e)) } // unpackEface converts the empty interface i to a Value.