]> Cypherpunks repositories - gostls13.git/commit
bytes, strings: add ASCII fast path to EqualFold
authorCharlie Vieth <charlie.vieth@gmail.com>
Wed, 24 Aug 2022 18:23:28 +0000 (14:23 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 21 Sep 2022 14:00:37 +0000 (14:00 +0000)
commitc70fd4b30aba5db2df7b5f6b0833c62b909f50eb
tree19030ad14b06d7a36219a7be71eca75c49f0df22
parent9c916c79011f3af98b5670eb2ba55349ba904522
bytes, strings: add ASCII fast path to EqualFold

This commit adds an ASCII fast path to bytes/strings EqualFold that
roughly doubles performance when all characters are ASCII.

It also changes strings.EqualFold to use `for range` for the first
string since this is ~10% faster than using utf8.DecodeRuneInString for
both (see #31666).

Performance (similar results on arm64 and amd64):

name                        old time/op  new time/op  delta
EqualFold/Tests-10           238ns ± 0%   172ns ± 1%  -27.91%  (p=0.000 n=10+10)
EqualFold/ASCII-10          20.5ns ± 0%   9.7ns ± 0%  -52.73%  (p=0.000 n=10+10)
EqualFold/UnicodePrefix-10  86.5ns ± 0%  77.6ns ± 0%  -10.37%  (p=0.000 n=10+10)
EqualFold/UnicodeSuffix-10  86.8ns ± 2%  71.3ns ± 0%  -17.88%  (p=0.000 n=10+8)

Change-Id: I058f3f97a08dc04d65af895674d85420f920abe1
Reviewed-on: https://go-review.googlesource.com/c/go/+/425459
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/bytes/bytes.go
src/strings/strings.go
src/strings/strings_test.go