Add "Extend Capacity"

Duncan Harris 2022-03-30 11:23:46 +01:00
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