mirror of
https://github.com/golang/go
synced 2024-11-17 02:54:45 -07: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:
parent
16e5d24480
commit
9e3b1d53a0
@ -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...)
|
||||
|
Loading…
Reference in New Issue
Block a user