aboutsummaryrefslogtreecommitdiff
path: root/http.go
diff options
context:
space:
mode:
authorGravatar Erik Dubbelboer <erik@dubbelboer.com> 2023-07-08 12:40:36 +0200
committerGravatar Erik Dubbelboer <erik@dubbelboer.com> 2023-07-08 12:40:36 +0200
commit1c85d43dfea23d49285c8248aff906c965062031 (patch)
tree38d827e13610680cf36ed01c4354490d7734c492 /http.go
parentAvoid nolint:errcheck in header tests (#1589) (diff)
downloadfasthttp-1c85d43dfea23d49285c8248aff906c965062031.tar.gz
fasthttp-1c85d43dfea23d49285c8248aff906c965062031.tar.bz2
fasthttp-1c85d43dfea23d49285c8248aff906c965062031.zip
Fix round2
- don't limit it to 32 bits - give it a proper name - don't over-allocate too much
Diffstat (limited to 'http.go')
-rw-r--r--http.go25
1 files changed, 2 insertions, 23 deletions
diff --git a/http.go b/http.go
index 5d8dc93..595eafa 100644
--- a/http.go
+++ b/http.go
@@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
- "math"
"mime/multipart"
"net"
"os"
@@ -2210,7 +2209,7 @@ func readBodyIdentity(r *bufio.Reader, maxBodySize int, dst []byte) ([]byte, err
return dst[:offset], ErrBodyTooLarge
}
if len(dst) == offset {
- n := round2(2 * offset)
+ n := roundUpForSliceCap(2 * offset)
if maxBodySize > 0 && n > maxBodySize {
n = maxBodySize + 1
}
@@ -2229,7 +2228,7 @@ func appendBodyFixedSize(r *bufio.Reader, dst []byte, n int) ([]byte, error) {
offset := len(dst)
dstLen := offset + n
if cap(dst) < dstLen {
- b := make([]byte, round2(dstLen))
+ b := make([]byte, roundUpForSliceCap(dstLen))
copy(b, dst)
dst = b
}
@@ -2339,26 +2338,6 @@ func readCrLf(r *bufio.Reader) error {
return nil
}
-func round2(n int) int {
- if n <= 0 {
- return 0
- }
-
- x := uint32(n - 1)
- x |= x >> 1
- x |= x >> 2
- x |= x >> 4
- x |= x >> 8
- x |= x >> 16
-
- // Make sure we don't return 0 due to overflow, even on 32 bit systems
- if x >= uint32(math.MaxInt32) {
- return math.MaxInt32
- }
-
- return int(x + 1)
-}
-
// SetTimeout sets timeout for the request.
//
// req.SetTimeout(t); c.Do(&req, &resp) is equivalent to