Skip to content

Commit

Permalink
opt: use the std math/bits routine to count the bit length (panjf2000…
Browse files Browse the repository at this point in the history
  • Loading branch information
0-haha committed Feb 5, 2023
1 parent 0f41b37 commit fbeb65d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/pool/ringbuffer/ringbuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package ringbuffer

import (
"math/bits"
"sort"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -160,9 +161,8 @@ func index(n int) int {
n--
n >>= minBitSize
idx := 0
for n > 0 {
n >>= 1
idx++
if n > 0 {
idx = bits.Len(uint(n))
}
if idx >= steps {
idx = steps - 1
Expand Down

0 comments on commit fbeb65d

Please sign in to comment.