mirror of https://github.com/panjf2000/ants.git
bug: avoid overflow when computing mid in the binarySearch of the workerStack (#278)
This commit is contained in:
parent
9fdd99a7b4
commit
67b3a7a2c3
|
@ -61,9 +61,8 @@ func (wq *workerStack) refresh(duration time.Duration) []worker {
|
|||
}
|
||||
|
||||
func (wq *workerStack) binarySearch(l, r int, expiryTime time.Time) int {
|
||||
var mid int
|
||||
for l <= r {
|
||||
mid = (l + r) / 2
|
||||
mid := int(uint(l+r) >> 1) // avoid overflow when computing mid
|
||||
if expiryTime.Before(wq.items[mid].lastUsedTime()) {
|
||||
r = mid - 1
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue