mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-13 15:46:49 +03:00
1c85d43dfe
- don't limit it to 32 bits - give it a proper name - don't over-allocate too much
25 lines
393 B
Go
25 lines
393 B
Go
//go:build amd64 || arm64 || ppc64 || ppc64le || s390x
|
|
// +build amd64 arm64 ppc64 ppc64le s390x
|
|
|
|
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
|
|
}
|
|
|
|
x := uint64(n - 1)
|
|
x |= x >> 1
|
|
x |= x >> 2
|
|
x |= x >> 4
|
|
x |= x >> 8
|
|
x |= x >> 16
|
|
|
|
return int(x + 1)
|
|
}
|