]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: make Value.IsZero not escape
authorCherry Mui <cherryyz@google.com>
Fri, 7 Oct 2022 22:11:10 +0000 (18:11 -0400)
committerCherry Mui <cherryyz@google.com>
Fri, 12 May 2023 21:13:39 +0000 (21:13 +0000)
With CL 408826 reflect.Value not always escape. IsZero still
escapes the Value because in some cases it passes the Value
pointer to the equal function, which is function pointer. Equal
functions are compiler generated and never escapes, but the escape
analysis doesn't know. Add noescape to help.

Change-Id: Ica397c2be77cac9e8a46d03d70bac385b0aa9e82
Reviewed-on: https://go-review.googlesource.com/c/go/+/441937
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/reflect/value.go

index b2b3fd1e3d6810a95604c18f6942f233b09a8f8b..616da6a5c7bcc6ede84d42b250432b97d5ab07ad 100644 (file)
@@ -1598,7 +1598,10 @@ func (v Value) IsZero() bool {
                        if v.flag&flagIndir == 0 {
                                return v.ptr == nil
                        }
-                       return v.typ().Equal(v.ptr, unsafe.Pointer(&zeroVal[0]))
+                       // v.ptr doesn't escape, as Equal functions are compiler generated
+                       // and never escape. The escape analysis doesn't know, as it is a
+                       // function pointer call.
+                       return v.typ().Equal(noescape(v.ptr), unsafe.Pointer(&zeroVal[0]))
                }
 
                n := v.Len()
@@ -1618,7 +1621,8 @@ func (v Value) IsZero() bool {
                        if v.flag&flagIndir == 0 {
                                return v.ptr == nil
                        }
-                       return v.typ().Equal(v.ptr, unsafe.Pointer(&zeroVal[0]))
+                       // See noescape justification above.
+                       return v.typ().Equal(noescape(v.ptr), unsafe.Pointer(&zeroVal[0]))
                }
 
                n := v.NumField()