1
0
mirror of https://github.com/golang/go synced 2024-09-29 09:24:28 -06:00

slices: document that Clone can return extra capacity

Change-Id: I8b9aa1f36ce554d8855ee70e15f0dd0a8cf1097a
Reviewed-on: https://go-review.googlesource.com/c/go/+/568342
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Ian Lance Taylor 2024-03-02 18:48:26 -08:00 committed by Gopher Robot
parent 16e5d24480
commit 9e3b1d53a0

View File

@ -342,6 +342,7 @@ func Replace[S ~[]E, E any](s S, i, j int, v ...E) S {
// Clone returns a copy of the slice.
// The elements are copied using assignment, so this is a shallow clone.
// The result may have additional unused capacity.
func Clone[S ~[]E, E any](s S) S {
// The s[:0:0] preserves nil in case it matters.
return append(s[:0:0], s...)