Implement standard debuggers.
These debug actions are added to all players by default.
This commit is contained in:
@ -145,3 +145,21 @@ func Strip[T any](slice []T, removeWhen func(idx int, t T) bool) []T {
|
||||
}
|
||||
return slice[:to]
|
||||
}
|
||||
|
||||
// EnsureCapacity checks if `cap(slice)` is at least req. If so, it returns
|
||||
// slice unchanged. Otherwise, it copies `slice` to a new slice that is at least
|
||||
// capacity `req` (but may be larger) and returns the copy.
|
||||
//
|
||||
// It is reasonably efficient to use EnsureCapacity consecutively without
|
||||
// regard for the final overall capacity that a specific slice will need to be.
|
||||
func EnsureCapacity[T any](slice []T, req int) []T {
|
||||
if cap(slice) >= req {
|
||||
return slice
|
||||
}
|
||||
if req < 2*cap(slice) {
|
||||
req = 2 * cap(slice)
|
||||
}
|
||||
ret := make([]T, len(slice), req)
|
||||
copy(ret, slice)
|
||||
return ret
|
||||
}
|
||||
|
Reference in New Issue
Block a user