Improve round2 performance (#914)

This commit is contained in:
kiyon
2020-11-20 00:52:42 +08:00
committed by GitHub
parent c2542e5acf
commit cb0aaaa266
+9 -7
View File
@@ -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)
}