File: round2_64.go

package info (click to toggle)
golang-github-valyala-fasthttp 1%3A1.59.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,932 kB
  • sloc: makefile: 34
file content (23 lines) | stat: -rw-r--r-- 392 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//go:build amd64 || arm64 || ppc64 || ppc64le || riscv64 || 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) // #nosec G115
	x |= x >> 1
	x |= x >> 2
	x |= x >> 4
	x |= x >> 8
	x |= x >> 16

	return int(x + 1) // #nosec G115
}