A little bit of optimization in periodicallyPurge()

This commit is contained in:
Andy Pan 2019-08-25 14:48:03 +08:00
parent cbf8ddf048
commit 44aec9954f
2 changed files with 4 additions and 6 deletions

View File

@ -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 {

View File

@ -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 {