aboutsummaryrefslogtreecommitdiff
path: root/src/reflect/all_test.go
diff options
context:
space:
mode:
authorJoe Tsai <joetsai@digital-static.net>2022-04-16 20:23:28 -0700
committerGopher Robot <gobot@golang.org>2022-04-18 22:14:50 +0000
commitc5edd5f616b4ee4bbaefdb1579c6078e7ed7e84e (patch)
tree32df92d62203cd08f36dc643530f2ff3e0ef4aee /src/reflect/all_test.go
parentf49e802892a225c7fd14a3a8bb8c0e83875d888d (diff)
downloadgo-c5edd5f616b4ee4bbaefdb1579c6078e7ed7e84e.tar.gz
go-c5edd5f616b4ee4bbaefdb1579c6078e7ed7e84e.zip
reflect: make Value.MapRange inlineable
This allows the caller to decide whether MapIter should be stack allocated or heap allocated based on whether it escapes. In most cases, it does not escape and thus removes the utility of MapIter.Reset (#46293). In fact, use of sync.Pool with MapIter and calling MapIter.Reset is likely to be slower. Change-Id: Ic93e7d39e5dd4c83e7fca9e0bdfbbcd70777f0e1 Reviewed-on: https://go-review.googlesource.com/c/go/+/400675 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/reflect/all_test.go')
-rw-r--r--src/reflect/all_test.go8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go
index 5a35d98b51..f7adf2fa1a 100644
--- a/src/reflect/all_test.go
+++ b/src/reflect/all_test.go
@@ -370,9 +370,11 @@ func TestMapIterSet(t *testing.T) {
e.SetIterValue(iter)
}
}))
- // Making a *MapIter allocates. This should be the only allocation.
- if got != 1 {
- t.Errorf("wanted 1 alloc, got %d", got)
+ // Calling MapRange should not allocate even though it returns a *MapIter.
+ // The function is inlineable, so if the local usage does not escape
+ // the *MapIter, it can remain stack allocated.
+ if got != 0 {
+ t.Errorf("wanted 0 alloc, got %d", got)
}
}