Implement standard debuggers.

These debug actions are added to all players by default.
This commit is contained in:
2023-04-15 19:16:08 -07:00
parent 22c4718faf
commit 74fac625f2
6 changed files with 241 additions and 14 deletions

View File

@ -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
}