aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/strings/replace.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2022-02-11 14:53:56 -0800
committerIan Lance Taylor <iant@golang.org>2022-02-11 15:01:19 -0800
commit8dc2499aa62f768c6395c9754b8cabc1ce25c494 (patch)
tree43d7fd2bbfd7ad8c9625a718a5e8718889351994 /libgo/go/strings/replace.go
parent9a56779dbc4e2d9c15be8d31e36f2f59be7331a8 (diff)
downloadgcc-8dc2499aa62f768c6395c9754b8cabc1ce25c494.zip
gcc-8dc2499aa62f768c6395c9754b8cabc1ce25c494.tar.gz
gcc-8dc2499aa62f768c6395c9754b8cabc1ce25c494.tar.bz2
libgo: update to Go1.18beta2
gotools/ * Makefile.am (go_cmd_cgo_files): Add ast_go118.go (check-go-tool): Copy golang.org/x/tools directories. * Makefile.in: Regenerate. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/384695
Diffstat (limited to 'libgo/go/strings/replace.go')
-rw-r--r--libgo/go/strings/replace.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/libgo/go/strings/replace.go b/libgo/go/strings/replace.go
index e28d428..ee728bb 100644
--- a/libgo/go/strings/replace.go
+++ b/libgo/go/strings/replace.go
@@ -387,7 +387,7 @@ func makeSingleStringReplacer(pattern string, value string) *singleStringReplace
}
func (r *singleStringReplacer) Replace(s string) string {
- var buf []byte
+ var buf Builder
i, matched := 0, false
for {
match := r.finder.next(s[i:])
@@ -395,15 +395,16 @@ func (r *singleStringReplacer) Replace(s string) string {
break
}
matched = true
- buf = append(buf, s[i:i+match]...)
- buf = append(buf, r.value...)
+ buf.Grow(match + len(r.value))
+ buf.WriteString(s[i : i+match])
+ buf.WriteString(r.value)
i += match + len(r.finder.pattern)
}
if !matched {
return s
}
- buf = append(buf, s[i:]...)
- return string(buf)
+ buf.WriteString(s[i:])
+ return buf.String()
}
func (r *singleStringReplacer) WriteString(w io.Writer, s string) (n int, err error) {