mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
Add "Extend Capacity"
parent
03aab308c4
commit
e832d1d424
@ -78,6 +78,14 @@ Append `n` elements:
|
||||
a = append(a, make([]T, n)...)
|
||||
```
|
||||
|
||||
#### Extend Capacity
|
||||
Make sure there is space to append `n` elements without re-allocating:
|
||||
```go
|
||||
if cap(a)-len(a) < n {
|
||||
a = append(make([]T, 0, len(a)+n), a...)
|
||||
}
|
||||
```
|
||||
|
||||
#### Filter (in place)
|
||||
|
||||
```go
|
||||
|
Loading…
x
Reference in New Issue
Block a user