mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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>
This commit is contained in:
parent
f49e802892
commit
c5edd5f616
3 changed files with 17 additions and 4 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue