aboutsummaryrefslogtreecommitdiff
path: root/src/strings/replace.go
AgeCommit message (Collapse)Author
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>
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>
2022-08-19strings: reduce allocation for byteReplacerCuong Manh Le
Though it increases the execution time, the function is already quite fast for most users, the allocation is much more important. name old time/op new time/op delta ByteReplacerWriteString-8 1.23µs ± 0% 2.16µs ± 1% +75.31% (p=0.000 n=10+10) name old alloc/op new alloc/op delta ByteReplacerWriteString-8 2.69kB ± 0% 0.00kB -100.00% (p=0.000 n=10+10) name old allocs/op new allocs/op delta ByteReplacerWriteString-8 1.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10) Change-Id: I6a36df5fcb8e11ef27e6c7b252aa88e869592f3c Reviewed-on: https://go-review.googlesource.com/c/go/+/424136 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Joedian Reid <joedian@golang.org>
2022-04-11all: gofmt main repoRuss Cox
[This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Run the updated gofmt, which reformats doc comments, on the main repository. Vendored files are excluded. For #51082. Change-Id: I7332f099b60f716295fb34719c98c04eb1a85407 Reviewed-on: https://go-review.googlesource.com/c/go/+/384268 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-08-22strings: smarter growth of temporal buffer and avoid copying on returnIgnacio Hagopian
The implementation for single strings had two optimization opportunities: 1. Grow the temporary buffer by known size before appending. 2. Avoid a full copy of the result since the underlying buffer won't be mutated afterward. Both things were leveraged by using a Builder instead of a byte slice. Relevant benchmark results: name old time/op new time/op delta SingleMatch-8 32.0µs ± 3% 26.1µs ± 3% -18.41% (p=0.000 n=9+10) name old speed new speed delta SingleMatch-8 469MB/s ± 3% 574MB/s ± 3% +22.56% (p=0.000 n=9+10) name old alloc/op new alloc/op delta SingleMatch-8 81.3kB ± 0% 49.0kB ± 0% -39.67% (p=0.000 n=10+10) name old allocs/op new allocs/op delta SingleMatch-8 19.0 ± 0% 11.0 ± 0% -42.11% (p=0.000 n=10+10) Change-Id: I23af56a15875206c0ff4ce29a51bec95fd48bb11 GitHub-Last-Rev: 403cfc3c2794b5da27792c51999417a2a052b365 GitHub-Pull-Request: golang/go#47766 Reviewed-on: https://go-review.googlesource.com/c/go/+/343089 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Robert Griesemer <gri@golang.org>
2019-07-10strings: document that order of pairs matters in NewReplacerFrancesco Renzi
Update NewReplacer documentation to specify that in the case of multiple matches at the same position, the matching old/new pair that appears first in NewReplacer arguments takes precedence. Fixes #32699 Change-Id: I9d0616d28e5cd8c9bfa301be201f2b0ebf361dff Reviewed-on: https://go-review.googlesource.com/c/go/+/185099 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2019-04-03strings: document that NewReplacer can panicBrad Fitzpatrick
Fixes #31233 Change-Id: I2831d5e6532d3f4ed7eb99af5d6e0e1a41ebac9a Reviewed-on: https://go-review.googlesource.com/c/go/+/170624 Reviewed-by: Andrew Bonventre <andybons@golang.org>
2018-10-13strings: Replace s[:] to s where s is a slice.Ivan Sharavuev
Change-Id: Ie7ba3f9ece9b0fc0e8a5c92fbae9c3b558815e4c Reviewed-on: https://go-review.googlesource.com/c/141997 Run-TryBot: Iskander Sharipov <iskander.sharipov@intel.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Iskander Sharipov <iskander.sharipov@intel.com>
2018-10-03io: export StringWriterDaniel Martí
And start using it elsewhere in the standard library, removing the copies in the process. While at it, rewrite the io.WriteString godoc to be more clear, since it can now make reference to the defined interface. Fixes #27946. Change-Id: Id5ba223c09c19e5fb49815bd3b1bd3254fc786f3 Reviewed-on: https://go-review.googlesource.com/c/139457 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-08-21strings: select Replacer algorithm and build machine lazilyBrad Fitzpatrick
Saves 22KB of memory in stdlib packages. Updates #26775 Change-Id: Ia19fe7aff61f6e2ddd83cd35969d7ff94526591f Reviewed-on: https://go-review.googlesource.com/127661 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-04-26strings: clarify Replacer's replacement orderAlberto Donizetti
NewReplacer's documentation says that "replacements are performed in order", meaning that substrings are replaced in the order they appear in the target string, and not that the old->new replacements are applied in the order they're passed to NewReplacer. Rephrase the doc to make this clearer. Fixes #25071 Change-Id: Icf3aa6a9d459b94764c9d577e4a76ad8c04d158d Reviewed-on: https://go-review.googlesource.com/109375 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-02strings: speed-up replace for byteStringReplacer caseIlya Tocar
Use Count instead of loop to determine a number of replacements. Also increment index instead of advancing slices, to avoid some extra stores. Shows very significant speed-up on html benchmarks: Escape-6 34.2µs ± 2% 20.8µs ± 2% -39.06% (p=0.000 n=10+10) EscapeNone-6 7.04µs ± 1% 1.05µs ± 0% -85.03% (p=0.000 n=10+10) On benchmarks in package strings results are still significant: ByteStringMatch-6 1.59µs ± 2% 1.17µs ± 2% -26.35% (p=0.000 n=10+10) HTMLEscapeNew-6 390ns ± 2% 337ns ± 2% -13.62% (p=0.000 n=10+10) HTMLEscapeOld-6 621ns ± 2% 603ns ± 2% -2.95% (p=0.000 n=10+9) Change-Id: Ibea3235b6e451ba72cd5db57716d17b917e72944 Reviewed-on: https://go-review.googlesource.com/97255 Run-TryBot: Ilya Tocar <ilya.tocar@intel.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2014-09-08build: move package sources from src/pkg to srcRuss Cox
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.