aboutsummaryrefslogtreecommitdiff
path: root/src/strings
AgeCommit message (Collapse)Author
21 hoursbytes,strings: add CutLastqiulaidongfeng
Fixes #71151 Change-Id: I3b3d49c35b0fa2c1220d3f39bbd506cc072b52b0 Reviewed-on: https://go-review.googlesource.com/c/go/+/764601 LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Sean Liao <sean@liao.dev> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com>
2026-03-12bytes,slices,strings: ContainsFunc: document short-circuit semanticsAlan Donovan
I assume this was the intent but was not documented as an oversight. Change-Id: I2d62b8b28ed7bca0d935788a39579b13d6503624 Reviewed-on: https://go-review.googlesource.com/c/go/+/754242 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Austin Clements <austin@google.com>
2026-02-03bytes, strings: replace asciiSet bitset with lookup tableCorentin Chary
Replace the 32-byte bitset implementation with a 256-byte lookup table for simpler and faster ASCII character membership testing. The bitset implementation used bit manipulation (shifts, masks, AND/OR) requiring multiple CPU operations per lookup. The lookup table uses direct array indexing with a single load and compare, reducing CPU overhead significantly. Using [256]bool instead of [256]byte allows the compiler to eliminate the comparison instruction entirely, as bool values are guaranteed to be either 0 or 1. The full 256-element array (rather than 128 elements) is used because it eliminates branches entirely. Testing shows [256]bool is 68% faster than [128]bool with an explicit bounds check (488µs vs 821µs) due to avoiding branch misprediction penalties in the hot path. Using [128]bool with bit masking (c&0x7f) eliminates bounds checks but still costs ~10% performance due to the AND operation. The 224-byte increase in memory usage is acceptable for modern systems, and the simpler implementation is easier to understand and maintain. Full benchmark results demonstrating ~1.5x improvements across all affected functions are available at: https://github.com/golang/go/issues/77194#issuecomment-3814095806 This supersedes CL 737920 with a simpler approach that improves performance for all architectures without requiring SIMD instructions. Updates #77194 Change-Id: I272ee6de05b963a8efc62e7e8838735fb0c4f41b Reviewed-on: https://go-review.googlesource.com/c/go/+/739982 Auto-Submit: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com>
2026-01-22strings: use bytealg.LastIndexRabinKarp on strings.LastIndexjiahua wang
Change-Id: I7eae15bf0b4d556763e1754e17031c880035d69c Reviewed-on: https://go-review.googlesource.com/c/go/+/538737 Auto-Submit: Sean Liao <sean@liao.dev> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Sean Liao <sean@liao.dev>
2025-11-03all: remove extra space in the commentscuishuang
Change-Id: I26302d801732f40b1fe6b30ff69d222047bca490 Reviewed-on: https://go-review.googlesource.com/c/go/+/716740 Reviewed-by: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-10-22comment: change slice to string in function comment/helpredteampanda-ng
Comment is outdated, it should say a string is returned Change-Id: I7d40135aac22845dbc1f91e02e5776cc7d58eda7 GitHub-Last-Rev: 08ee556f0803dc0e2a765d431ac10758b4f26146 GitHub-Pull-Request: golang/go#75980 Reviewed-on: https://go-review.googlesource.com/c/go/+/713040 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Keith Randall <khr@google.com>
2025-09-16bytes,strings: remove reference to non-existent SplitFuncSean Liao
Fixes #75462 Updates #72841 Change-Id: Ie2cbbdb031578a3138ecc6e60c0025807f1990e6 Reviewed-on: https://go-review.googlesource.com/c/go/+/703675 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
2025-09-15all: replace strings.Split with strings.SplitSeq1911860538
In Go 1.25+, strings.SplitSeq offers better performance. Here are the benchmark results comparing strings.Split and strings.SplitSeq in a for-loop, with the benchmark code located in src/strings/iter_test.go: goos: darwin goarch: amd64 pkg: cmd/go/internal/auth cpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ ParseGitAuth/standard-8 281.4n ± 1% 218.0n ± 11% -22.54% (p=0.000 n=10) ParseGitAuth/with_url-8 549.1n ± 1% 480.5n ± 13% -12.48% (p=0.002 n=10) ParseGitAuth/minimal-8 235.4n ± 1% 197.3n ± 7% -16.20% (p=0.000 n=10) ParseGitAuth/complex-8 797.6n ± 2% 805.2n ± 4% ~ (p=0.481 n=10) ParseGitAuth/empty-8 87.48n ± 3% 63.25n ± 6% -27.71% (p=0.000 n=10) ParseGitAuth/malformed-8 228.8n ± 1% 171.2n ± 3% -25.17% (p=0.000 n=10) geomean 288.9n 237.7n -17.72% │ old.txt │ new.txt │ │ B/op │ B/op vs base │ ParseGitAuth/standard-8 192.00 ± 0% 96.00 ± 0% -50.00% (p=0.000 n=10) ParseGitAuth/with_url-8 400.0 ± 0% 288.0 ± 0% -28.00% (p=0.000 n=10) ParseGitAuth/minimal-8 144.00 ± 0% 80.00 ± 0% -44.44% (p=0.000 n=10) ParseGitAuth/complex-8 528.0 ± 0% 400.0 ± 0% -24.24% (p=0.000 n=10) ParseGitAuth/empty-8 32.00 ± 0% 16.00 ± 0% -50.00% (p=0.000 n=10) ParseGitAuth/malformed-8 176.00 ± 0% 80.00 ± 0% -54.55% (p=0.000 n=10) geomean 179.0 102.1 -42.96% │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ ParseGitAuth/standard-8 3.000 ± 0% 2.000 ± 0% -33.33% (p=0.000 n=10) ParseGitAuth/with_url-8 4.000 ± 0% 3.000 ± 0% -25.00% (p=0.000 n=10) ParseGitAuth/minimal-8 3.000 ± 0% 2.000 ± 0% -33.33% (p=0.000 n=10) ParseGitAuth/complex-8 4.000 ± 0% 3.000 ± 0% -25.00% (p=0.000 n=10) ParseGitAuth/empty-8 2.000 ± 0% 1.000 ± 0% -50.00% (p=0.000 n=10) ParseGitAuth/malformed-8 3.000 ± 0% 2.000 ± 0% -33.33% (p=0.000 n=10) geomean 3.086 2.040 -33.91% Updates #69315. Change-Id: Id0219edea45d9658d527b863162ebe917e7821d9 GitHub-Last-Rev: 392b315e122f2c9ef8703ca2dbce8f82ec198556 GitHub-Pull-Request: golang/go#75259 Reviewed-on: https://go-review.googlesource.com/c/go/+/701015 Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Emmanuel Odeke <emmanuel@orijtech.com>
2025-09-03unicode/utf8: make DecodeRune{,InString} inlineableJulien Cretel
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: 2e352a0045027e059be79cdb60241b5cf35fec71 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-08-29bytes, strings: speed up TrimSpaceJulien Cretel
This change lifts bounds checks out of loops in the TrimSpace functions, among other micro-optimizations. Here are some benchmark results (no change to allocations): goos: darwin goarch: amd64 pkg: bytes cpu: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz │ old │ new │ │ sec/op │ sec/op vs base │ TrimSpace/NoTrim-8 4.406n ± 0% 3.829n ± 1% -13.11% (p=0.000 n=20) TrimSpace/ASCII-8 7.688n ± 1% 5.872n ± 1% -23.61% (p=0.000 n=20) TrimSpace/SomeNonASCII-8 82.25n ± 1% 81.00n ± 1% -1.51% (p=0.001 n=20) TrimSpace/JustNonASCII-8 131.6n ± 8% 132.2n ± 1% ~ (p=0.899 n=20) geomean 24.61n 22.15n -9.99% pkg: strings │ old │ new │ │ sec/op │ sec/op vs base │ TrimSpace/NoTrim-8 4.178n ± 0% 3.857n ± 2% -7.68% (p=0.001 n=20) TrimSpace/ASCII-8 7.708n ± 0% 5.585n ± 1% -27.55% (p=0.000 n=20) TrimSpace/SomeNonASCII-8 98.70n ± 1% 88.54n ± 1% -10.30% (p=0.000 n=20) TrimSpace/JustNonASCII-8 132.8n ± 2% 123.2n ± 0% -7.16% (p=0.000 n=20) geomean 25.49n 22.02n -13.61% Change-Id: I523f03a909c82a51940b44c7b2634985b7447982 GitHub-Last-Rev: 35163f04c63ce2ef5e9e831c4371750504edb892 GitHub-Pull-Request: golang/go#75127 Reviewed-on: https://go-review.googlesource.com/c/go/+/698735 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> Auto-Submit: Sean Liao <sean@liao.dev> Reviewed-by: Keith Randall <khr@google.com>
2025-08-28strings: remove redundant "runs" from string.Fields docstringBrad
Change-Id: I502b24af186fc56fe953acf7ab7d29f8eefb9c07 GitHub-Last-Rev: 1a4edf431217d9c9ebf78f228926c297e51dd54a GitHub-Pull-Request: golang/go#75156 Reviewed-on: https://go-review.googlesource.com/c/go/+/699215 Reviewed-by: Sean Liao <sean@liao.dev> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Sean Liao <sean@liao.dev> Reviewed-by: Florian Lehner <lehner.florian86@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-05-19strings,bytes: add internal docs about perennial noCopy questionsAlan Donovan
Updates #26462 Updates #25907 Updates #47276 Updates #48398 Change-Id: Ic64fc8d0c284f6e5aa383a8d417fa5768dcd7925 Reviewed-on: https://go-review.googlesource.com/c/go/+/674096 Auto-Submit: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-05-15strings,bytes: make benchmark work deterministicKeith Randall
It's hard to compare two different runs of a benchmark if they are doing different amounts of work. Change-Id: I5d6845f3d11bb10136f745e6207d5f683612276d Reviewed-on: https://go-review.googlesource.com/c/go/+/672895 Reviewed-by: Junyang Shao <shaojunyang@google.com> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-14bytes, strings: speed up Split{,After}SeqJulien Cretel
CL 669735 brought a welcome performance boost to splitSeq; however, it rendered explodeSeq ineligible for inlining and failed to update that function's doc comment. This CL inlines the call to explodeSeq in splitSeq, thereby unlocking a further speedup in the case of an empty separator, and removes function explodeSeq altogether. Some benchmarks results: goos: darwin goarch: amd64 pkg: strings cpu: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz │ old │ new │ │ sec/op │ sec/op vs base │ SplitSeqEmptySeparator-8 5.136m ± 6% 3.180m ± 6% -38.09% (p=0.000 n=20) SplitSeqSingleByteSeparator-8 995.9µ ± 1% 988.4µ ± 0% -0.75% (p=0.000 n=20) SplitSeqMultiByteSeparator-8 593.1µ ± 2% 591.7µ ± 1% ~ (p=0.253 n=20) SplitAfterSeqEmptySeparator-8 5.554m ± 3% 3.432m ± 2% -38.20% (p=0.000 n=20) SplitAfterSeqSingleByteSeparator-8 997.4µ ± 0% 1000.0µ ± 8% ~ (p=0.121 n=20) SplitAfterSeqMultiByteSeparator-8 591.7µ ± 1% 588.9µ ± 0% -0.48% (p=0.004 n=20) geomean 1.466m 1.247m -14.97% │ old │ new │ │ B/op │ B/op vs base │ SplitSeqEmptySeparator-8 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ SplitSeqSingleByteSeparator-8 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ SplitSeqMultiByteSeparator-8 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ SplitAfterSeqEmptySeparator-8 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ SplitAfterSeqSingleByteSeparator-8 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ SplitAfterSeqMultiByteSeparator-8 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20) ¹ geomean ² +0.00% ² ¹ all samples are equal ² summaries must be >0 to compute geomean Change-Id: I5767b68dc1a4fbcb2ac20683830a49ee3eb1bee1 GitHub-Last-Rev: 344934071f3220a1afea3def306dadfee720d311 GitHub-Pull-Request: golang/go#73685 Reviewed-on: https://go-review.googlesource.com/c/go/+/672175 Reviewed-by: qiu laidongfeng2 <2645477756@qq.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2025-05-12bytes, strings: rename parameters in ExampleCut{Pre,Suf}fixTobias Klauser
The old parameter name sep was probably copied from ExampleCut. Change the parameter names to prefix and suffix, respectivly to make the examples a bit more readable. Change-Id: Ie14b0050c2fafe3301c5368efd548a1629a7545f Reviewed-on: https://go-review.googlesource.com/c/go/+/670955 Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Sean Liao <sean@liao.dev> Reviewed-by: Robert Griesemer <gri@google.com>
2025-05-12bytes, strings: micro-optimize EqualFoldJulien Cretel
The first loop leaves the lengths of the two arguments unchanged. Take advantage of this invariant in the loop's condition. Here are some benchmark results (no change to allocations): goos: darwin goarch: amd64 pkg: strings cpu: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz │ old │ new │ │ sec/op │ sec/op vs base │ EqualFold/Tests-8 240.0n ± 4% 245.1n ± 5% ~ (p=0.516 n=20) EqualFold/ASCII-8 11.50n ± 1% 11.04n ± 0% -3.96% (p=0.000 n=20) EqualFold/UnicodePrefix-8 102.1n ± 0% 102.2n ± 0% ~ (p=0.455 n=20) EqualFold/UnicodeSuffix-8 90.14n ± 0% 89.80n ± 1% ~ (p=0.113 n=20) geomean 71.00n 70.60n -0.56% Change-Id: I1f6d1df8a0398f9493692f59d7369c3f0fbba436 GitHub-Last-Rev: 9508ee26ad3cadcbb5e532a731b2553ba900f2b1 GitHub-Pull-Request: golang/go#73672 Reviewed-on: https://go-review.googlesource.com/c/go/+/671756 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-05bytes, strings: reduce Split{,After}Seq heap allocationstdakkota
This CL slightly changes flow of splitSeq to help compiler to inline the iterator closure. goos: linux goarch: amd64 pkg: strings cpu: AMD Ryzen 9 5950X 16-Core Processor │ sec/op │ sec/op vs base │ SplitSeqEmptySeparator-32 3.590m ± 0% 3.430m ± 2% -4.46% (p=0.000 n=30) SplitSeqSingleByteSeparator-32 647.0µ ± 0% 656.1µ ± 0% +1.41% (p=0.000 n=30) SplitSeqMultiByteSeparator-32 423.9µ ± 1% 384.5µ ± 0% -9.31% (p=0.000 n=30) SplitAfterSeqEmptySeparator-32 3.372m ± 4% 3.514m ± 0% +4.20% (p=0.000 n=30) SplitAfterSeqSingleByteSeparator-32 648.5µ ± 2% 537.6µ ± 0% -17.10% (p=0.000 n=30) SplitAfterSeqMultiByteSeparator-32 423.3µ ± 2% 364.4µ ± 2% -13.91% (p=0.000 n=30) geomean 984.7µ 917.3µ -6.85% │ B/op │ B/op vs base │ SplitSeqEmptySeparator-32 24.00 ± 0% 0.00 ± 0% -100.00% (p=0.000 n=30) SplitSeqSingleByteSeparator-32 24.00 ± 0% 0.00 ± 0% -100.00% (p=0.000 n=30) SplitSeqMultiByteSeparator-32 24.00 ± 0% 0.00 ± 0% -100.00% (p=0.000 n=30) SplitAfterSeqEmptySeparator-32 24.00 ± 0% 0.00 ± 0% -100.00% (p=0.000 n=30) SplitAfterSeqSingleByteSeparator-32 24.00 ± 0% 0.00 ± 0% -100.00% (p=0.000 n=30) SplitAfterSeqMultiByteSeparator-32 24.00 ± 0% 0.00 ± 0% -100.00% (p=0.000 n=30) geomean 24.00 ? For #73524 Change-Id: Ic83c5751a41c65030356a208e4ad1f500723e695 Reviewed-on: https://go-review.googlesource.com/c/go/+/669735 Auto-Submit: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: qiu laidongfeng2 <2645477756@qq.com> Commit-Queue: Alan Donovan <adonovan@google.com>
2025-04-15strings: duplicate alignment test from bytes packageConstantin Konstantinidis
Fixes #26129 Change-Id: If98f85b458990dbff7ecfeaea6c81699dafa66ef Reviewed-on: https://go-review.googlesource.com/c/go/+/665275 Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-03-20strings: don't assert on Replace's allocs for ASANJulien Cretel
CL 657935 caused failures on the ASAN builder. Under ASAN, do not assert on the number of allocations incurred by Replace. Fixes #72973 Change-Id: I61536be6def6f2489d2a026c943c6e232865b723 GitHub-Last-Rev: 4aee3c2560c9a6fa6ba7c1950acc2172a7cfffe4 GitHub-Pull-Request: golang/go#72975 Reviewed-on: https://go-review.googlesource.com/c/go/+/659696 Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jorropo <jorropo.pgm@gmail.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
2025-03-20strings: speed up ReplaceJulien Cretel
Add benchmarks for Replace. The length of parameter old does not change. Move the corresponding length check outside the loop. Use range-over-int loops where possible. Some benchmark results (no changes to allocations): goos: darwin goarch: amd64 pkg: strings cpu: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz │ old │ new │ │ sec/op │ sec/op vs base │ Replace/"hello"_"l"_"L"_0-8 6.102n ± 6% 6.139n ± 5% ~ (p=0.644 n=20) Replace/"hello"_"l"_"L"_-1-8 62.81n ± 1% 63.30n ± 1% ~ (p=0.098 n=20) Replace/"hello"_"x"_"X"_-1-8 12.19n ± 0% 12.49n ± 0% +2.50% (p=0.000 n=20) Replace/""_"x"_"X"_-1-8 12.20n ± 0% 12.51n ± 0% +2.58% (p=0.000 n=20) Replace/"radar"_"r"_"<r>"_-1-8 69.65n ± 0% 66.57n ± 0% -4.43% (p=0.000 n=20) Replace/""_""_"<>"_-1-8 39.54n ± 1% 35.84n ± 1% -9.34% (p=0.000 n=20) Replace/"banana"_"a"_"<>"_-1-8 79.95n ± 0% 79.21n ± 0% -0.93% (p=0.000 n=20) Replace/"banana"_"a"_"<>"_1-8 48.67n ± 1% 49.45n ± 0% +1.60% (p=0.000 n=20) Replace/"banana"_"a"_"<>"_1000-8 80.28n ± 1% 79.52n ± 0% -0.95% (p=0.000 n=20) Replace/"banana"_"an"_"<>"_-1-8 82.89n ± 1% 84.62n ± 1% +2.09% (p=0.000 n=20) Replace/"banana"_"ana"_"<>"_-1-8 56.45n ± 1% 57.41n ± 1% +1.69% (p=0.000 n=20) Replace/"banana"_""_"<>"_-1-8 114.5n ± 1% 104.8n ± 0% -8.52% (p=0.000 n=20) Replace/"banana"_""_"<>"_10-8 114.5n ± 0% 104.8n ± 0% -8.43% (p=0.000 n=20) Replace/"banana"_""_"<>"_6-8 104.00n ± 0% 95.43n ± 0% -8.24% (p=0.000 n=20) Replace/"banana"_""_"<>"_5-8 91.85n ± 1% 83.68n ± 1% -8.89% (p=0.000 n=20) Replace/"banana"_""_"<>"_1-8 43.73n ± 1% 40.17n ± 0% -8.13% (p=0.000 n=20) Replace/"banana"_"a"_"a"_-1-8 4.410n ± 0% 4.443n ± 0% +0.76% (p=0.000 n=20) Replace/"banana"_"a"_"a"_1-8 4.395n ± 0% 4.423n ± 1% +0.64% (p=0.022 n=20) Replace/"☺☻☹"_""_"<>"_-1-8 98.58n ± 0% 91.66n ± 0% -7.02% (p=0.000 n=20) geomean 39.72n 38.59n -2.83% Change-Id: Ia0c7798b24d95d7c98b488a6d4ce7e78de76db9d GitHub-Last-Rev: 644fe36dcbe46b6a22febea5fe2cd566572b879c GitHub-Pull-Request: golang/go#72868 Reviewed-on: https://go-review.googlesource.com/c/go/+/657935 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-03-18bytes,strings: document Fields trimming of leading and trailing charactersSean Liao
Fixes #72841 Change-Id: I46875c61e3147c69da759bf4bf4f0539cbd4f437 Reviewed-on: https://go-review.googlesource.com/c/go/+/658218 Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-03-15strings: add FuzzReplace testJorropo
While reviewing CL 657935 I've notied there a couple tricky reslices that depends on multiple things being correct. Might as well fuzz it. Change-Id: Id78921bcb252e73a8a06e6deb4c920445a87d525 Reviewed-on: https://go-review.googlesource.com/c/go/+/658075 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2025-02-19bytes,strings: remove redundant return statement for LinesJes Cok
To make it more idiomatic. Change-Id: If48ae9931908e515df7f23185aac6f84aac72084 GitHub-Last-Rev: 525ed5031a08388f637bd2a09bd47c9e25df21f1 GitHub-Pull-Request: golang/go#71838 Reviewed-on: https://go-review.googlesource.com/c/go/+/650595 Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Commit-Queue: Ian Lance Taylor <iant@golang.org> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Commit-Queue: Robert Griesemer <gri@google.com>
2025-02-10strings: add examples for Lines, SplitSeq, SplitAfterSeq, FieldsSeq and ↵cuishuang
FieldsFuncSeq Change-Id: I1e5085ff2ed7f3d75ac3dc34ab72be6b55729fb7 Reviewed-on: https://go-review.googlesource.com/c/go/+/647575 Auto-Submit: Ian Lance Taylor <iant@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-12-17bytes, strings: add cross-references in docstringsOleksandr Redko
For newly funcs SplitSeq, SplitAfterSeq, FieldsSeq, FieldsFuncSeq. Updates #61901. Change-Id: I3c97bfd9c2250de68aaea348c82a05635ee797af Reviewed-on: https://go-review.googlesource.com/c/go/+/637176 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-10-28all: skip and fix various tests with -asan and -msanMichael Anthony Knyszek
First, skip all the allocation count tests. In some cases this aligns with existing skips for -race, but in others we've got new issues. These are debug modes, so some performance loss is expected, and this is clearly no worse than today where the tests fail. Next, skip internal linking and static linking tests for msan and asan. With asan we get an explicit failure that neither are supported by the C and/or Go compilers. With msan, we only get the Go compiler telling us internal linking is unavailable. With static linking, we segfault instead. Filed #70080 to track that. Next, skip some malloc tests with asan that don't quite work because of the redzone. This is because of some sizeclass assumptions that get broken with the redzone and the fact that the tiny allocator is effectively disabled (again, due to the redzone). Next, skip some runtime/pprof tests with asan, because of extra allocations. Next, skip some malloc tests with asan that also fail because of extra allocations. Next, fix up memstats accounting for arenas when asan is enabled. There is a bug where more is added to the stats than subtracted. This also simplifies the accounting a little. Next, skip race tests with msan or asan enabled; they're mutually incompatible. Fixes #70054. Fixes #64256. Fixes #64257. For #70079. For #70080. Change-Id: I99c02a0b9d621e44f1f918b307aa4a4944c3ec60 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-asan-clang15,gotip-linux-amd64-msan-clang15 Reviewed-on: https://go-review.googlesource.com/c/go/+/622855 Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Bypass: Michael Knyszek <mknyszek@google.com>
2024-08-19all: remove duplicated words in commentsOleksandr Redko
Change-Id: Id991ec0826a4e2857f00330b4b7ff2b71907b789 Reviewed-on: https://go-review.googlesource.com/c/go/+/606615 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com>
2024-08-16strings: fix typo in examplesGökhan Özeloğlu
The correct word can be seen in lines 381-382. Change-Id: If3876bd34b6433b69531763f63af88d60a0bfad0 Reviewed-on: https://go-review.googlesource.com/c/go/+/606375 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org>
2024-08-14byte,strings: improve IndexRune performance by ~45%Charlie Vieth
Change IndexRune to search for the last byte of a multi-byte rune instead of using the first byte. This improves search performance by 45% on average when dealing with Unicode text. The rationale here is that the last byte of a UTF-8 encoded multi-byte rune is significantly more unique (evenly distributed) than the first byte which has a 78% chance of being [240, 243, 244]. This approach is typically much faster, but can be slower when there are a large number of false positives (see Han benchmarks) because the more even distribution of bytes can delay/prevent falling back to a brute-force search using bytealg.Index, which is particularly powerful on amd64/x86_64 (particularly Skylake, but less so with newer processors). bytes package benchmarks: goos: darwin goarch: arm64 pkg: bytes cpu: Apple M1 Max │ base.10.txt │ new.10.txt │ │ sec/op │ sec/op vs base │ IndexRune/10-10 9.784n ± 0% 8.470n ± 0% -13.43% (p=0.000 n=10) IndexRune/32-10 11.660n ± 0% 8.473n ± 0% -27.34% (p=0.000 n=10) IndexRune/4K-10 83.96n ± 0% 81.08n ± 0% -3.44% (p=0.000 n=10) IndexRune/4M-10 63.92µ ± 0% 64.67µ ± 0% +1.17% (p=0.000 n=10) IndexRune/64M-10 1.121m ± 1% 1.125m ± 1% ~ (p=0.218 n=10) IndexRuneUnicode/Latin/10-10 10.125n ± 0% 7.347n ± 0% -27.43% (p=0.000 n=10) IndexRuneUnicode/Latin/32-10 11.435n ± 0% 7.349n ± 0% -35.73% (p=0.000 n=10) IndexRuneUnicode/Latin/4K-10 882.6n ± 0% 334.9n ± 1% -62.06% (p=0.000 n=10) IndexRuneUnicode/Latin/4M-10 977.2µ ± 0% 370.9µ ± 1% -62.04% (p=0.000 n=10) IndexRuneUnicode/Latin/64M-10 15.649m ± 1% 6.028m ± 1% -61.48% (p=0.000 n=10) IndexRuneUnicode/Cyrillic/10-10 10.070n ± 0% 8.701n ± 0% -13.59% (p=0.000 n=10) IndexRuneUnicode/Cyrillic/32-10 19.045n ± 0% 8.704n ± 1% -54.30% (p=0.000 n=10) IndexRuneUnicode/Cyrillic/4K-10 2.734µ ± 0% 1.046µ ± 1% -61.75% (p=0.000 n=10) IndexRuneUnicode/Cyrillic/4M-10 2.671m ± 0% 1.143m ± 1% -57.22% (p=0.000 n=10) IndexRuneUnicode/Cyrillic/64M-10 43.12m ± 1% 18.26m ± 1% -57.64% (p=0.000 n=10) IndexRuneUnicode/Han/10-10 10.10n ± 0% 10.82n ± 1% +7.08% (p=0.000 n=10) IndexRuneUnicode/Han/32-10 38.29n ± 1% 10.87n ± 1% -71.62% (p=0.000 n=10) IndexRuneUnicode/Han/4K-10 1409.0n ± 0% 489.1n ± 1% -65.28% (p=0.000 n=10) IndexRuneUnicode/Han/4M-10 1338.4µ ± 0% 821.1µ ± 2% -38.65% (p=0.000 n=10) IndexRuneUnicode/Han/64M-10 21.42m ± 1% 13.42m ± 2% -37.34% (p=0.000 n=10) geomean 3.983µ 2.305µ -42.14% │ base.10.txt │ new.10.txt │ │ B/s │ B/s vs base │ IndexRune/10-10 974.8Mi ± 0% 1126.1Mi ± 0% +15.52% (p=0.000 n=10) IndexRune/32-10 2.556Gi ± 0% 3.517Gi ± 0% +37.62% (p=0.000 n=10) IndexRune/4K-10 45.43Gi ± 0% 47.05Gi ± 0% +3.56% (p=0.000 n=10) IndexRune/4M-10 61.12Gi ± 0% 60.41Gi ± 0% -1.16% (p=0.000 n=10) IndexRune/64M-10 55.74Gi ± 1% 55.57Gi ± 1% ~ (p=0.218 n=10) IndexRuneUnicode/Latin/10-10 942.0Mi ± 0% 1297.9Mi ± 0% +37.78% (p=0.000 n=10) IndexRuneUnicode/Latin/32-10 2.606Gi ± 0% 4.055Gi ± 0% +55.61% (p=0.000 n=10) IndexRuneUnicode/Latin/4K-10 4.322Gi ± 0% 11.392Gi ± 1% +163.57% (p=0.000 n=10) IndexRuneUnicode/Latin/4M-10 3.998Gi ± 0% 10.532Gi ± 1% +163.47% (p=0.000 n=10) IndexRuneUnicode/Latin/64M-10 3.994Gi ± 1% 10.369Gi ± 1% +159.61% (p=0.000 n=10) IndexRuneUnicode/Cyrillic/10-10 947.2Mi ± 0% 1096.1Mi ± 0% +15.72% (p=0.000 n=10) IndexRuneUnicode/Cyrillic/32-10 1.565Gi ± 0% 3.424Gi ± 1% +118.80% (p=0.000 n=10) IndexRuneUnicode/Cyrillic/4K-10 1.396Gi ± 0% 3.649Gi ± 1% +161.43% (p=0.000 n=10) IndexRuneUnicode/Cyrillic/4M-10 1.462Gi ± 0% 3.418Gi ± 1% +133.76% (p=0.000 n=10) IndexRuneUnicode/Cyrillic/64M-10 1.450Gi ± 1% 3.422Gi ± 1% +136.08% (p=0.000 n=10) IndexRuneUnicode/Han/10-10 944.6Mi ± 0% 881.7Mi ± 1% -6.66% (p=0.000 n=10) IndexRuneUnicode/Han/32-10 797.0Mi ± 1% 2809.3Mi ± 1% +252.47% (p=0.000 n=10) IndexRuneUnicode/Han/4K-10 2.707Gi ± 0% 7.798Gi ± 1% +188.04% (p=0.000 n=10) IndexRuneUnicode/Han/4M-10 2.919Gi ± 0% 4.757Gi ± 2% +63.01% (p=0.000 n=10) IndexRuneUnicode/Han/64M-10 2.917Gi ± 1% 4.656Gi ± 2% +59.60% (p=0.000 n=10) geomean 3.036Gi 5.246Gi +72.82% goos: linux goarch: amd64 pkg: bytes │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ IndexRune/10-4 10.805n ± 0% 6.999n ± 0% -35.22% (p=0.000 n=10) IndexRune/32-4 12.515n ± 0% 7.539n ± 0% -39.76% (p=0.000 n=10) IndexRune/4K-4 71.69n ± 0% 68.39n ± 0% -4.60% (p=0.000 n=10) IndexRune/4M-4 125.19µ ± 2% 63.05µ ± 0% -49.63% (p=0.000 n=10) IndexRune/64M-4 1.050m ± 1% 1.053m ± 0% ~ (p=0.353 n=10) IndexRuneUnicode/Latin/10-4 9.471n ± 0% 6.144n ± 1% -35.13% (p=0.000 n=10) IndexRuneUnicode/Latin/32-4 12.540n ± 0% 6.655n ± 0% -46.93% (p=0.000 n=10) IndexRuneUnicode/Latin/4K-4 522.1n ± 0% 207.2n ± 0% -60.32% (p=0.000 n=10) IndexRuneUnicode/Latin/4M-4 626.1µ ± 0% 297.2µ ± 0% -52.54% (p=0.000 n=10) IndexRuneUnicode/Latin/64M-4 13.866m ± 3% 5.069m ± 4% -63.44% (p=0.000 n=10) IndexRuneUnicode/Cyrillic/10-4 10.920n ± 0% 7.213n ± 0% -33.95% (p=0.000 n=10) IndexRuneUnicode/Cyrillic/32-4 12.515n ± 0% 7.780n ± 0% -37.83% (p=0.000 n=10) IndexRuneUnicode/Cyrillic/4K-4 2650.0n ± 0% 621.5n ± 0% -76.55% (p=0.000 n=10) IndexRuneUnicode/Cyrillic/4M-4 2744.7µ ± 0% 723.2µ ± 0% -73.65% (p=0.000 n=10) IndexRuneUnicode/Cyrillic/64M-4 44.18m ± 0% 14.22m ± 14% -67.82% (p=0.000 n=10) IndexRuneUnicode/Han/10-4 10.795n ± 0% 9.734n ± 1% -9.83% (p=0.000 n=10) IndexRuneUnicode/Han/32-4 12.79n ± 0% 10.42n ± 1% -18.46% (p=0.000 n=10) IndexRuneUnicode/Han/4K-4 519.7n ± 0% 288.4n ± 0% -44.51% (p=0.000 n=10) IndexRuneUnicode/Han/4M-4 498.2µ ± 0% 443.0µ ± 0% -11.07% (p=0.000 n=10) IndexRuneUnicode/Han/64M-4 9.654m ± 2% 12.223m ± 1% +26.61% (p=0.000 n=10) geomean 3.168µ 1.828µ -42.30% │ old.txt │ new.txt │ │ B/s │ B/s vs base │ IndexRune/10-4 882.5Mi ± 0% 1362.6Mi ± 0% +54.41% (p=0.000 n=10) IndexRune/32-4 2.381Gi ± 0% 3.953Gi ± 0% +66.00% (p=0.000 n=10) IndexRune/4K-4 53.21Gi ± 0% 55.77Gi ± 0% +4.82% (p=0.000 n=10) IndexRune/4M-4 31.20Gi ± 2% 61.95Gi ± 0% +98.55% (p=0.000 n=10) IndexRune/64M-4 59.54Gi ± 1% 59.37Gi ± 0% ~ (p=0.353 n=10) IndexRuneUnicode/Latin/10-4 1006.9Mi ± 0% 1552.3Mi ± 1% +54.17% (p=0.000 n=10) IndexRuneUnicode/Latin/32-4 2.376Gi ± 0% 4.478Gi ± 0% +88.45% (p=0.000 n=10) IndexRuneUnicode/Latin/4K-4 7.306Gi ± 0% 18.411Gi ± 0% +152.01% (p=0.000 n=10) IndexRuneUnicode/Latin/4M-4 6.239Gi ± 0% 13.145Gi ± 0% +110.70% (p=0.000 n=10) IndexRuneUnicode/Latin/64M-4 4.507Gi ± 3% 12.329Gi ± 4% +173.54% (p=0.000 n=10) IndexRuneUnicode/Cyrillic/10-4 873.0Mi ± 0% 1322.2Mi ± 0% +51.46% (p=0.000 n=10) IndexRuneUnicode/Cyrillic/32-4 2.382Gi ± 0% 3.831Gi ± 0% +60.84% (p=0.000 n=10) IndexRuneUnicode/Cyrillic/4K-4 1.439Gi ± 0% 6.138Gi ± 0% +326.43% (p=0.000 n=10) IndexRuneUnicode/Cyrillic/4M-4 1.423Gi ± 0% 5.401Gi ± 0% +279.52% (p=0.000 n=10) IndexRuneUnicode/Cyrillic/64M-4 1.415Gi ± 0% 4.396Gi ± 17% +210.79% (p=0.000 n=10) IndexRuneUnicode/Han/10-4 883.4Mi ± 0% 979.7Mi ± 1% +10.90% (p=0.000 n=10) IndexRuneUnicode/Han/32-4 2.331Gi ± 0% 2.858Gi ± 1% +22.61% (p=0.000 n=10) IndexRuneUnicode/Han/4K-4 7.340Gi ± 0% 13.226Gi ± 0% +80.19% (p=0.000 n=10) IndexRuneUnicode/Han/4M-4 7.841Gi ± 0% 8.817Gi ± 0% +12.44% (p=0.000 n=10) IndexRuneUnicode/Han/64M-4 6.474Gi ± 2% 5.113Gi ± 1% -21.02% (p=0.000 n=10) geomean 3.816Gi 6.614Gi +73.32% strings package benchmarks: goos: darwin goarch: arm64 pkg: strings │ base.index_rune.10.txt │ new.index_rune.10.txt │ │ sec/op │ sec/op vs base │ IndexRune-10 11.905n ± 5% 6.633n ± 6% -44.28% (p=0.000 n=10) IndexRuneLongString-10 13.800n ± 1% 7.330n ± 2% -46.88% (p=0.000 n=10) IndexRuneFastPath-10 3.477n ± 0% 3.481n ± 1% ~ (p=0.468 n=10) geomean 8.297n 5.531n -33.34% Change-Id: I59357fda1c8ac85315b759930f620dbce1ba4721 Reviewed-on: https://go-review.googlesource.com/c/go/+/539116 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-08-14bytes, strings: add Lines, SplitSeq, SplitAfterSeq, FieldsSeq, FieldsFuncSeqaimuz
Fixes #61901. Change-Id: I4db21c91fd21079f2aa3bc81fb03dd6f40423a38 GitHub-Last-Rev: ed3df560a40ea10cdcb8ad476ba6849463f3c761 GitHub-Pull-Request: golang/go#67543 Reviewed-on: https://go-review.googlesource.com/c/go/+/587095 Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-08-07bytes,strings: use a more universal Cyrillic wordOleksandr Redko
The word "брат" (brother) is the same across Slavic languages that use the Cyrillic script, such as Bulgarian, Macedonian, Russian, Ukrainian, and others. Change-Id: I5155e6bb16a02dec5d93a01b79f9570f43f09444 Reviewed-on: https://go-review.googlesource.com/c/go/+/603535 Reviewed-by: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: David Chase <drchase@google.com>
2024-08-05bytes, strings: replace reflect.DeepEqual and custom eq with slices.Equal in ↵aimuz
tests Change-Id: I016672af79d49a00ddc2d0449cdaac61e98b4ba0 GitHub-Last-Rev: 38d15d9a03e5bd29e4b25f1d767e40cf7165a7a6 GitHub-Pull-Request: golang/go#68730 Reviewed-on: https://go-review.googlesource.com/c/go/+/602698 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-08-01bytes,slices,strings: optimize Repeat a bitJes Cok
Like slices.Repeat, use math/bits.Mul to detect overflow in order to avoid a divide which is slow. While here, also use builtin min/max to simplify code. Change-Id: I4a6d8cd5df97fa75f4e324d4be1405ce53c03d31 GitHub-Last-Rev: 54ba5c7126b1d4a301e95d664b5f6deee6d579d9 GitHub-Pull-Request: golang/go#68704 Reviewed-on: https://go-review.googlesource.com/c/go/+/602475 Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2024-07-24bytes,strings,unicode/utf16: use slices to clean up testsapocelipes
Replace reflect.DeepEqual with slices.Equal, which is much faster. Remove some redundant helper functions. Change-Id: I51b32a3d0c3fc5ad0d3b6ff0dd03f39c507e5762 GitHub-Last-Rev: e21f46d4a026b6bf6e8d912dfb8d361a20a4e779 GitHub-Pull-Request: golang/go#67609 Reviewed-on: https://go-review.googlesource.com/c/go/+/587937 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Griesemer <gri@google.com>
2024-07-22cmd/compile: don't inline runtime functions in -d=checkptr buildCherry Mui
Runtime functions, e.g. internal/abi.NoEscape, should not be instrumented with checkptr. But if they are inlined into a checkptr-enabled function, they will be instrumented, and may result in a check failure. Let the compiler not inline runtime functions into checkptr- enabled functions. Also undo the change in the strings package in CL 598295, as the compiler handles it now. Fixes #68511. Updates #68415. Change-Id: I78eb380855ac9dd53c1a1a628ec0da75c3e5a1a0 Reviewed-on: https://go-review.googlesource.com/c/go/+/599435 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com>
2024-07-16regexp: more cross-references in docstringsKir Kolyshkin
Change-Id: I93f617bb6d82b00d44ce9a54c2ddcc8a61209783 Reviewed-on: https://go-review.googlesource.com/c/go/+/597776 Reviewed-by: Than McIntosh <thanm@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2024-07-16strings,bytes,regexp: use lists in Split* docstringsKir Kolyshkin
This looks better than the default of using a code block. While at it, fix punctuation. Change-Id: I86abca4da1e9999b7e9043e615ad0988d35a5a46 Reviewed-on: https://go-review.googlesource.com/c/go/+/597656 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-07-15strings: re-introduce noescape wrapperCuong Manh Le
CL 573955 added internal/abi:NoEscape function, and use it in strings builder copyCheck code. However, internal/abi is a runtime package, which can not be built with -d=checkptr flag yet. This causes incorrect inlining decision, since NoEscape must not be inlined when -d=checkptr is used. Fixing this by re-introducing noescape wrapper. Fixes #68415 Change-Id: I776cab4c9e9e4b3e58162dcce6ec025cb366bdee Reviewed-on: https://go-review.googlesource.com/c/go/+/598295 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Jorropo <jorropo.pgm@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2024-07-11strings: more cross-references in docstringsKir Kolyshkin
This amends CL 534775. Change-Id: I25a217da51853ec29106998e19e9386d756902fc Reviewed-on: https://go-review.googlesource.com/c/go/+/597655 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-05-04strings: move Clone to stringsliteqiulaidongfeng
Follow-up CL help package like unique use Clone. Change-Id: Ie64adf7e1a331f47c3cfe178c368d72fc72493ff GitHub-Last-Rev: 499476cc4acdf58ecf0fec9f7281bfb90edc7c82 GitHub-Pull-Request: golang/go#67106 Reviewed-on: https://go-review.googlesource.com/c/go/+/581956 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org>
2024-05-03strings: move TrimPrefix and TrimSuffix to stringsliteapocelipes
To help packages use these functions like "os" which using the copied function "stringsTrimSuffix". Change-Id: I223028ed264c7b7e95534b4883223af0988cda68 GitHub-Last-Rev: 2fd8fbf5286e5a4abdb03704d69f02e32d3f1a6b GitHub-Pull-Request: golang/go#67151 Reviewed-on: https://go-review.googlesource.com/c/go/+/583075 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: qiu laidongfeng2 <2645477756@qq.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-05-03strings,bytes: improve Repeat panic messagesgo101
The Repeat("-", maxInt) call should produce panic: runtime error: makeslice: len out of range instead of panic: strings: Repeat output length overflow This PR is only for theory perfection. Change-Id: If67d87b147d666fbbb7238656f2a0cb6cf1dbb5b GitHub-Last-Rev: 29dc0cb9c9c63d8a008960b4527d6aa6798c1c17 GitHub-Pull-Request: golang/go#67068 Reviewed-on: https://go-review.googlesource.com/c/go/+/581936 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-04-26strings, internal/stringslite: lite version of strings packageDamien Neil
To be used by internal/filepathlite, which is to be used by os. There are probably other places where it would be convenient to have strings functions accessible to RUNTIME level packages. Change-Id: Icda59e7a9e26d9e8f3692db0ea4fb7b3dbf570d7 Reviewed-on: https://go-review.googlesource.com/c/go/+/581516 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-04-17internal/abi: define EmptyInterface, TypeOf, and NoEscapeMichael Anthony Knyszek
This change defines two commonly-defined functions and a commonly-defined type in internal/abi to try and deduplicate some definitions. This is motivated by a follow-up CL which will want access to TypeOf in yet another package. There still exist duplicate definitions of all three of these things in the runtime, and this CL doesn't try to handle that yet. There are far too many uses in the runtime to handle manually in a way that feels comfortable; automated refactoring will help. For #62483. Change-Id: I02fc64a28f11af618f6071f94d27f45c135fa8ac Reviewed-on: https://go-review.googlesource.com/c/go/+/573955 Auto-Submit: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
2024-04-04strings: intrinsify and optimize CompareEmma Haruka Iwao
slices.SortFunc requires a three-way comparison and we need an efficient strings.Compare to perform three-way string comparisons. This new implementation adds bytealg.CompareString as a wrapper of runtime_cmpstring and changes Compare to use bytealg.CompareString. The new implementation of Compare with runtime_cmpstring is about 28% faster than the previous one. Fixes #61725 │ /tmp/gobench-sort-cmp.txt │ /tmp/gobench-sort-strings.txt │ │ sec/op │ sec/op vs base │ SortFuncStruct/Size16-48 918.8n ± 1% 726.6n ± 0% -20.92% (p=0.000 n=10) SortFuncStruct/Size32-48 2.666µ ± 1% 2.003µ ± 1% -24.85% (p=0.000 n=10) SortFuncStruct/Size64-48 1.934µ ± 1% 1.331µ ± 1% -31.22% (p=0.000 n=10) SortFuncStruct/Size128-48 3.560µ ± 1% 2.423µ ± 0% -31.94% (p=0.000 n=10) SortFuncStruct/Size512-48 13.019µ ± 0% 9.071µ ± 0% -30.33% (p=0.000 n=10) SortFuncStruct/Size1024-48 25.61µ ± 0% 17.75µ ± 0% -30.70% (p=0.000 n=10) geomean 4.217µ 3.018µ -28.44% Change-Id: I2513b6f8c1b9b273ef2d23f0a86f691e2d097eb6 Reviewed-on: https://go-review.googlesource.com/c/go/+/532195 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: qiu laidongfeng2 <2645477756@qq.com> Reviewed-by: Keith Randall <khr@google.com>
2024-03-18strings: optimize Repeat for common substringsJoe Tsai
According to static analysis of Go source code known by the module proxy, spaces, dashes, zeros, and tabs are the most commonly repeated string literals. Out of ~69k total calls to Repeat: * ~25k calls are repeats of " " * ~7k calls are repeats of "-" * ~4k calls are repeats of "0" * ~2k calls are repeats of "=" * ~2k calls are repeats of "\t" After this optimization, ~60% of Repeat calls will go through the fast path. These are often used in padding of fixed-width terminal UI or in the presentation of humanly readable text (e.g., indentation made of spaces or tabs). Optimize for this case by handling short repeated sequences of common literals. Performance: name old time/op new time/op delta RepeatSpaces-24 19.3ns ± 1% 5.0ns ± 1% -74.27% (p=0.000 n=8+9) name old alloc/op new alloc/op delta RepeatSpaces-24 2.00B ± 0% 0.00B -100.00% (p=0.000 n=10+10) name old allocs/op new allocs/op delta RepeatSpaces-24 1.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10) Change-Id: Id1cafd0cc509e835c8241a626489eb206e0adc3c Reviewed-on: https://go-review.googlesource.com/c/go/+/536615 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Than McIntosh <thanm@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-19strings: make use of sizeclasses in (*Builder).GrowMateusz Poliwczak
Fixes #64833 Change-Id: Ice3f5dfab65f5525bc7a6f57ddeaabda8d64dfa3 GitHub-Last-Rev: 38f1d6c19d8ec29ae5645ce677839a301f798df3 GitHub-Pull-Request: golang/go#64835 Reviewed-on: https://go-review.googlesource.com/c/go/+/552135 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-11-20src: a/an grammar fixesVille Skyttä
Change-Id: I179b50ae8e73677d4d408b83424afbbfe6aa17a1 GitHub-Last-Rev: 2e2d9c1e45556155d02db4df381b99f2d1bc5c0e GitHub-Pull-Request: golang/go#63478 Reviewed-on: https://go-review.googlesource.com/c/go/+/534015 Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-10-13bytes,strings: add available godoc linkcui fliter
Change-Id: Id9706a783d3321e3706eeee102286522e7968efd Reviewed-on: https://go-review.googlesource.com/c/go/+/534775 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-10-09bytes,strings: add example for ContainsFunccui fliter
Change-Id: I340e892aa4ecc780905be984016efc86699a45a2 Reviewed-on: https://go-review.googlesource.com/c/go/+/533556 Run-TryBot: shuang cui <imcusg@gmail.com> Reviewed-by: qiulaidongfeng <2645477756@qq.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>