From f7f496025ad3af839502585c595e5a7bc1b2839c Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 12 Feb 2024 17:10:43 -0800 Subject: [PATCH] types/views: add test that LenIter doesn't allocate For a second we thought this was allocating but we were looking at a CPU profile (which showed calls to mallocgc view makeslice) instead of the alloc profile. Updates golang/go#65685 (which if fixed wouldn't have confused us) Change-Id: Ic0132310d52d8a65758a516142525339aa23b1ed Signed-off-by: Brad Fitzpatrick --- types/views/views_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/types/views/views_test.go b/types/views/views_test.go index 5b3f07733..e3d5cbda9 100644 --- a/types/views/views_test.go +++ b/types/views/views_test.go @@ -151,6 +151,15 @@ func TestLenIter(t *testing.T) { if !reflect.DeepEqual(orig, got) { t.Errorf("got %q; want %q", got, orig) } + x := 0 + n := testing.AllocsPerRun(10000, func() { + for range v.LenIter() { + x++ + } + }) + if n > 0 { + t.Errorf("allocs = %v; want 0", n) + } } func TestSliceEqual(t *testing.T) {