go/src/unicode
Julien Cretel 925a3cdcd1 unicode/utf8: make DecodeRune{,InString} inlineable
This change makes the fast path for ASCII characters inlineable in
DecodeRune and DecodeRuneInString and removes most instances of manual
inlining at call sites.

Here are some benchmark results (no change to allocations):

goos: darwin
goarch: amd64
pkg: unicode/utf8
cpu: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
                             │     old      │                 new                  │
                             │    sec/op    │    sec/op     vs base                │
DecodeASCIIRune-8              2.4545n ± 2%   0.6253n ± 2%  -74.52% (p=0.000 n=20)
DecodeJapaneseRune-8            3.988n ± 1%    4.023n ± 1%   +0.86% (p=0.050 n=20)
DecodeASCIIRuneInString-8      2.4675n ± 1%   0.6264n ± 2%  -74.61% (p=0.000 n=20)
DecodeJapaneseRuneInString-8    3.992n ± 1%    4.001n ± 1%        ~ (p=0.625 n=20)
geomean                         3.134n         1.585n       -49.43%

Note: when #61502 gets resolved, DecodeRune and DecodeRuneInString should
be reverted to their idiomatic implementations.

Fixes #31666
Updates #48195

Change-Id: I4be25c4f52417dc28b3a7bd72f1b04018470f39d
GitHub-Last-Rev: 2e352a0045
GitHub-Pull-Request: golang/go#75181
Reviewed-on: https://go-review.googlesource.com/c/go/+/699675
Reviewed-by: Sean Liao <sean@liao.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
2025-09-03 07:04:47 -07:00
..
utf8 unicode/utf8: make DecodeRune{,InString} inlineable 2025-09-03 07:04:47 -07:00
utf16 bytes,strings,unicode/utf16: use slices to clean up tests 2024-07-24 18:45:08 +00:00
casetables.go
digit.go
digit_test.go
example_test.go unicode: use IsSpace not IsUpper in IsSpace example test 2021-10-08 00:18:29 +00:00
graphic.go unicode: add available godoc link 2023-11-06 20:02:46 +00:00
graphic_test.go
letter.go unicode: improve SimpleFold performance by 2x for non-foldable code points 2024-09-03 20:54:56 +00:00
letter_test.go unicode: improve SimpleFold performance by 2x for non-foldable code points 2024-09-03 20:54:56 +00:00
script_test.go unicode: add CategoryAliases, Cn, LC 2025-04-18 14:13:31 -07:00
tables.go unicode: add CategoryAliases, Cn, LC 2025-04-18 14:13:31 -07:00