From 9bd34ebb7e820922458929c9a1146fb0a5b0ca4d Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Sat, 14 Sep 2024 06:37:33 +0700 Subject: [PATCH] unicode/utf8: add test that RuneCount does zero allocations See disccusion in CL 612955. Change-Id: I2de582321648f1798929ffb80d2f087e41146ead Reviewed-on: https://go-review.googlesource.com/c/go/+/613315 Commit-Queue: Ian Lance Taylor Reviewed-by: Tim King Reviewed-by: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI Auto-Submit: Cuong Manh Le --- src/unicode/utf8/utf8_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/unicode/utf8/utf8_test.go b/src/unicode/utf8/utf8_test.go index 2adec97541..69362d2cf1 100644 --- a/src/unicode/utf8/utf8_test.go +++ b/src/unicode/utf8/utf8_test.go @@ -438,6 +438,15 @@ func TestRuneCount(t *testing.T) { } } +func TestRuneCountNonASCIIAllocation(t *testing.T) { + if n := testing.AllocsPerRun(10, func() { + s := []byte("日本語日本語日本語日") + _ = RuneCount(s) + }); n > 0 { + t.Errorf("unexpected RuneCount allocation, got %v, want 0", n) + } +} + type RuneLenTest struct { r rune size int -- 2.48.1