Skip to content

Commit

Permalink
Improve round2 performance (#914)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiyonlin authored Nov 19, 2020
1 parent c2542e5 commit cb0aaaa
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -1956,11 +1956,13 @@ func round2(n int) int {
if n <= 0 {
return 0
}
n--
x := uint(0)
for n > 0 {
n >>= 1
x++
}
return 1 << x

x := uint32(n - 1)
x |= x >> 1
x |= x >> 2
x |= x >> 4
x |= x >> 8
x |= x >> 16

return int(x + 1)
}

0 comments on commit cb0aaaa

Please sign in to comment.