round2_64.go 393 B

123456789101112131415161718192021222324
  1. //go:build amd64 || arm64 || ppc64 || ppc64le || s390x
  2. // +build amd64 arm64 ppc64 ppc64le s390x
  3. package fasthttp
  4. func roundUpForSliceCap(n int) int {
  5. if n <= 0 {
  6. return 0
  7. }
  8. // Above 100MB, we don't round up as the overhead is too large.
  9. if n > 100*1024*1024 {
  10. return n
  11. }
  12. x := uint64(n - 1)
  13. x |= x >> 1
  14. x |= x >> 2
  15. x |= x >> 4
  16. x |= x >> 8
  17. x |= x >> 16
  18. return int(x + 1)
  19. }