From: Cuong Manh Le Date: Fri, 13 Sep 2024 23:37:33 +0000 (+0700) Subject: unicode/utf8: add test that RuneCount does zero allocations X-Git-Tag: go1.24rc1~899 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=9bd34ebb7e820922458929c9a1146fb0a5b0ca4d;p=gostls13.git 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 --- 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