]> Cypherpunks repositories - gostls13.git/commitdiff
unicode/utf8: add test that RuneCount does zero allocations
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Fri, 13 Sep 2024 23:37:33 +0000 (06:37 +0700)
committerGopher Robot <gobot@golang.org>
Sun, 15 Sep 2024 02:04:55 +0000 (02:04 +0000)
See disccusion in CL 612955.

Change-Id: I2de582321648f1798929ffb80d2f087e41146ead
Reviewed-on: https://go-review.googlesource.com/c/go/+/613315
Commit-Queue: Ian Lance Taylor <iant@google.com>
Reviewed-by: Tim King <taking@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>

src/unicode/utf8/utf8_test.go

index 2adec9754154405e932d596631b01c3a484afc4c..69362d2cf1af6c7a8ef4cce315610dce15b36224 100644 (file)
@@ -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