go/src/strings
Anuraag Agrawal 9503bcae2b strings: reuse the input string for Repeat count of 1
The existing implementation allocates a new string even when the
count is 1, where we know the output is the same as the input.
While we wouldn't expect a count of 1 for hardcoded values of the
parameter, it is expected when the parameter is computed based on
a different value (e.g., the length of a input slice).

name            old time/op  new time/op  delta
Repeat/5x0-10   2.03ns ± 0%  2.02ns ± 0%   ~     (p=1.000 n=1+1)
Repeat/5x1-10   13.7ns ± 0%   2.0ns ± 0%   ~     (p=1.000 n=1+1)
Repeat/5x2-10   18.2ns ± 0%  18.1ns ± 0%   ~     (p=1.000 n=1+1)
Repeat/5x6-10   27.0ns ± 0%  27.0ns ± 0%   ~     (p=1.000 n=1+1)
Repeat/10x0-10  2.02ns ± 0%  2.02ns ± 0%   ~     (p=1.000 n=1+1)
Repeat/10x1-10  16.1ns ± 0%   2.0ns ± 0%   ~     (p=1.000 n=1+1)
Repeat/10x2-10  20.8ns ± 0%  20.9ns ± 0%   ~     (p=1.000 n=1+1)
Repeat/10x6-10  29.2ns ± 0%  29.4ns ± 0%   ~     (p=1.000 n=1+1)

Change-Id: I48e08e08f8f6d6914d62b3d6a61d563d637bec59
GitHub-Last-Rev: 068f58e08b
GitHub-Pull-Request: golang/go#53321
Reviewed-on: https://go-review.googlesource.com/c/go/+/411477
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Keith Randall <khr@google.com>
2022-09-14 14:56:07 +00:00
..
builder.go strings: simplify code using unsafe.StringData 2022-09-07 01:33:55 +00:00
builder_test.go strings: add a test case of growLen is negative 2022-09-13 17:39:52 +00:00
clone.go strings: simplify code using unsafe.StringData 2022-09-07 01:33:55 +00:00
clone_test.go strings: simplify code using unsafe.StringData 2022-09-07 01:33:55 +00:00
compare.go net/netip: add new IP address package 2021-11-02 01:28:01 +00:00
compare_test.go strings: simplify code using unsafe.StringData 2022-09-07 01:33:55 +00:00
example_test.go strings: document the use of simple case-folding in EqualFold 2022-04-02 06:48:45 +00:00
export_test.go all: gofmt -w -r 'interface{} -> any' src 2021-12-13 18:45:54 +00:00
reader.go
reader_test.go all: gofmt -w -r 'interface{} -> any' src 2021-12-13 18:45:54 +00:00
replace.go strings: reduce allocation for byteReplacer 2022-08-19 16:32:49 +00:00
replace_test.go
search.go
search_test.go
strings.go strings: reuse the input string for Repeat count of 1 2022-09-14 14:56:07 +00:00
strings_test.go strings: reuse the input string for Repeat count of 1 2022-09-14 14:56:07 +00:00