mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
Updated SliceTricks (markdown)
parent
ee9fc72909
commit
96c559eddd
@ -107,12 +107,15 @@ a = append(a[:i], append(b, a[i:]...)...)
|
|||||||
|
|
||||||
// The above one-line way copies a[i:] twice and
|
// The above one-line way copies a[i:] twice and
|
||||||
// allocates at least once.
|
// allocates at least once.
|
||||||
// The following verbose way only copy elements
|
// The following verbose way only copies elements
|
||||||
// in a[i:] once and allocates at most once.
|
// in a[i:] once and allocates at most once.
|
||||||
// But, as of Go toolchain 1.16, due to lacking of
|
// But, as of Go toolchain 1.16, due to lacking of
|
||||||
// optimizations to avoid elements clearing in the
|
// optimizations to avoid elements clearing in the
|
||||||
// "make" call, the verbose way is not always faster.
|
// "make" call, the verbose way is not always faster.
|
||||||
//
|
//
|
||||||
|
// Future compiler optimizations might implement
|
||||||
|
// both in the most efficient ways.
|
||||||
|
//
|
||||||
// Assume element type is int.
|
// Assume element type is int.
|
||||||
func Insert(s []int, k int, vs ...int) []int {
|
func Insert(s []int, k int, vs ...int) []int {
|
||||||
if n := len(s) + len(vs); n <= cap(s) {
|
if n := len(s) + len(vs); n <= cap(s) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user