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()
idleWorkers := p.workers
n := len(idleWorkers)
i := 0
for i < n && currentTime.Sub(idleWorkers[i].recycleTime) > p.expiryDuration {
i++
var i int
for i = 0; i < n && currentTime.Sub(idleWorkers[i].recycleTime) > p.expiryDuration; i++ {
}
expiredWorkers = append(expiredWorkers[:0], idleWorkers[:i]...)
if i > 0 {

View File

@ -92,9 +92,8 @@ func (p *PoolWithFunc) periodicallyPurge() {
p.lock.Lock()
idleWorkers := p.workers
n := len(idleWorkers)
i := 0
for i < n && currentTime.Sub(idleWorkers[i].recycleTime) > p.expiryDuration {
i++
var i int
for i = 0; i < n && currentTime.Sub(idleWorkers[i].recycleTime) > p.expiryDuration; i++ {
}
expiredWorkers = append(expiredWorkers[:0], idleWorkers[:i]...)
if i > 0 {