mirror of
https://github.com/golang/go
synced 2024-11-16 21:24:53 -07:00
slices: avoid an unnecessary check in Replace
The current implementation of the builtin copy function will return early
when it is found that the addresses of the first elements of the two
slice arguments are identical, so it is unnecessarily to do this in user code.
See #57759 for details.
Change-Id: I7c101eee496923d7aa59f94720da6c84feb93af8
GitHub-Last-Rev: 4d6819fb25
GitHub-Pull-Request: golang/go#63617
Reviewed-on: https://go-review.googlesource.com/c/go/+/536255
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@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Keith Randall <khr@google.com>
This commit is contained in:
parent
1c5862cc0a
commit
f3a2459caa
@ -268,9 +268,7 @@ func Replace[S ~[]E, E any](s S, i, j int, v ...E) S {
|
||||
if i+len(v) <= j {
|
||||
// Easy, as v fits in the deleted portion.
|
||||
copy(r[i:], v)
|
||||
if i+len(v) != j {
|
||||
copy(r[i+len(v):], s[j:])
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user