2024-09-26 01:59:44 +00:00
|
|
|
//go:build amd64 || arm64 || ppc64 || ppc64le || riscv64 || s390x
|
2024-09-17 01:01:42 +00:00
|
|
|
|
|
|
|
package fasthttp
|
|
|
|
|
|
|
|
func roundUpForSliceCap(n int) int {
|
|
|
|
if n <= 0 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// Above 100MB, we don't round up as the overhead is too large.
|
|
|
|
if n > 100*1024*1024 {
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
2024-09-26 01:59:44 +00:00
|
|
|
x := uint64(n - 1) // #nosec G115
|
2024-09-17 01:01:42 +00:00
|
|
|
x |= x >> 1
|
|
|
|
x |= x >> 2
|
|
|
|
x |= x >> 4
|
|
|
|
x |= x >> 8
|
|
|
|
x |= x >> 16
|
|
|
|
|
2024-09-26 01:59:44 +00:00
|
|
|
return int(x + 1) // #nosec G115
|
2024-09-17 01:01:42 +00:00
|
|
|
}
|