round2_64.go 351 B

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