aboutsummaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2023-11-16 01:01:58 -0500
committerCherry Mui <cherryyz@google.com>2023-11-16 19:25:34 +0000
commit0434ca9ce87eb06c6b8ba42fa09eaee0dda8d381 (patch)
tree973266d6f8e33206e7ef3009940103183ed16538 /src/reflect
parent23ca33009571a55eda926b7a41f5ceb04277bbd9 (diff)
downloadgo-0434ca9ce87eb06c6b8ba42fa09eaee0dda8d381.tar.xz
reflect: uncomment allocation test
We no longer force Value content to escape and the compiler's escape analysis can handle it now. Change-Id: I0628f3241e6ef37dce710c2394725e280790479a Reviewed-on: https://go-review.googlesource.com/c/go/+/542975 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/all_test.go28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go
index bece56f7e7..71969106e4 100644
--- a/src/reflect/all_test.go
+++ b/src/reflect/all_test.go
@@ -3503,16 +3503,24 @@ func TestAllocations(t *testing.T) {
var i any
var v Value
- // We can uncomment this when compiler escape analysis
- // is good enough to see that the integer assigned to i
- // does not escape and therefore need not be allocated.
- //
- // i = 42 + j
- // v = ValueOf(i)
- // if int(v.Int()) != 42+j {
- // panic("wrong int")
- // }
-
+ i = 42 + j
+ v = ValueOf(i)
+ if int(v.Int()) != 42+j {
+ panic("wrong int")
+ }
+ })
+ noAlloc(t, 100, func(j int) {
+ var i any
+ var v Value
+ i = [3]int{j, j, j}
+ v = ValueOf(i)
+ if v.Len() != 3 {
+ panic("wrong length")
+ }
+ })
+ noAlloc(t, 100, func(j int) {
+ var i any
+ var v Value
i = func(j int) int { return j }
v = ValueOf(i)
if v.Interface().(func(int) int)(j) != j {