From f3a2459caa2bd360fee782de8cf8d4de724a7316 Mon Sep 17 00:00:00 2001 From: go101 Date: Wed, 18 Oct 2023 17:17:18 +0000 Subject: [PATCH] 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: 4d6819fb25143f5ad3ff65eca7fe6094c37f2af2 GitHub-Pull-Request: golang/go#63617 Reviewed-on: https://go-review.googlesource.com/c/go/+/536255 Auto-Submit: Keith Randall LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall Reviewed-by: Ian Lance Taylor Reviewed-by: Keith Randall --- src/slices/slices.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/slices/slices.go b/src/slices/slices.go index 252a8eecfc..465af14f8e 100644 --- a/src/slices/slices.go +++ b/src/slices/slices.go @@ -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:]) - } + copy(r[i+len(v):], s[j:]) return r } -- 2.50.0