-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🥕 dns, slicehelper: prefer slices package
slices.Grow is better because it exposes all additional capacity from rounding up to the next size class.
- Loading branch information
1 parent
99e4174
commit e2bd5ff
Showing
2 changed files
with
5 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,11 @@ | ||
package slicehelper | ||
|
||
import "slices" | ||
|
||
// Extend extends the input slice by n elements. head is the full extended | ||
// slice, while tail is the appended part. If the original slice has sufficient | ||
// capacity no allocation is performed. | ||
func Extend[S ~[]E, E any](in S, n int) (head, tail S) { | ||
if total := len(in) + n; cap(in) >= total { | ||
head = in[:total] | ||
} else { | ||
head = make(S, total) | ||
copy(head, in) | ||
} | ||
tail = head[len(in):] | ||
return | ||
head = slices.Grow(in, n)[:len(in)+n] | ||
return head, head[len(in):] | ||
} |