forked from mirror/ants
A little bit of optimization in periodicallyPurge()
This commit is contained in:
parent
cbf8ddf048
commit
44aec9954f
5
pool.go
5
pool.go
|
@ -89,9 +89,8 @@ func (p *Pool) periodicallyPurge() {
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
idleWorkers := p.workers
|
idleWorkers := p.workers
|
||||||
n := len(idleWorkers)
|
n := len(idleWorkers)
|
||||||
i := 0
|
var i int
|
||||||
for i < n && currentTime.Sub(idleWorkers[i].recycleTime) > p.expiryDuration {
|
for i = 0; i < n && currentTime.Sub(idleWorkers[i].recycleTime) > p.expiryDuration; i++ {
|
||||||
i++
|
|
||||||
}
|
}
|
||||||
expiredWorkers = append(expiredWorkers[:0], idleWorkers[:i]...)
|
expiredWorkers = append(expiredWorkers[:0], idleWorkers[:i]...)
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
|
|
|
@ -92,9 +92,8 @@ func (p *PoolWithFunc) periodicallyPurge() {
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
idleWorkers := p.workers
|
idleWorkers := p.workers
|
||||||
n := len(idleWorkers)
|
n := len(idleWorkers)
|
||||||
i := 0
|
var i int
|
||||||
for i < n && currentTime.Sub(idleWorkers[i].recycleTime) > p.expiryDuration {
|
for i = 0; i < n && currentTime.Sub(idleWorkers[i].recycleTime) > p.expiryDuration; i++ {
|
||||||
i++
|
|
||||||
}
|
}
|
||||||
expiredWorkers = append(expiredWorkers[:0], idleWorkers[:i]...)
|
expiredWorkers = append(expiredWorkers[:0], idleWorkers[:i]...)
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
|
|
Loading…
Reference in New Issue