go/src/bytes
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
..
boundary_test.go bytes: add a boundary test for Count of 1 byte 2023-11-30 20:05:58 +00:00
buffer.go strings,bytes: add internal docs about perennial noCopy questions 2025-05-19 10:38:56 -07:00
buffer_test.go std: pass bytes.Buffer and strings.Builder by pointer 2025-05-19 09:13:04 -07:00
bytes.go unicode/utf8: make DecodeRune{,InString} inlineable 2025-09-03 07:04:47 -07:00
bytes_js_wasm_test.go internal/bytealg: extend memchr result correctly on wasm 2024-07-17 07:00:20 +00:00
bytes_test.go all: omit unnecessary type conversions 2025-07-28 11:13:58 -07:00
compare_test.go bytes: remove builders check from compare test 2023-07-13 23:11:42 +00:00
example_test.go bytes, strings: rename parameters in ExampleCut{Pre,Suf}fix 2025-05-12 09:07:54 -07:00
export_test.go bytes, internal/bytealg: simplify Equal 2019-04-24 00:56:36 +00:00
iter.go unicode/utf8: make DecodeRune{,InString} inlineable 2025-09-03 07:04:47 -07:00
iter_test.go bytes, strings: reduce Split{,After}Seq heap allocations 2025-05-05 19:08:23 -07:00
reader.go bytes: more cross-references in docstrings 2024-07-16 18:17:37 +00:00
reader_test.go all: gofmt -w -r 'interface{} -> any' src 2021-12-13 18:45:54 +00:00