optimization for #7

This commit is contained in:
Andy Pan 2018-08-08 21:44:01 +08:00
parent 50918eb4a9
commit e51be35d84
2 changed files with 8 additions and 12 deletions

View File

@ -77,13 +77,11 @@ func (p *Pool) periodicallyPurge() {
idleWorkers[i] = nil idleWorkers[i] = nil
} }
n++ n++
if n > 0 {
if n >= len(idleWorkers) { if n >= len(idleWorkers) {
p.workers = idleWorkers[:0] p.workers = idleWorkers[:0]
} else { } else {
p.workers = idleWorkers[n:] p.workers = idleWorkers[n:]
} }
}
p.lock.Unlock() p.lock.Unlock()
} }
} }

View File

@ -78,13 +78,11 @@ func (p *PoolWithFunc) periodicallyPurge() {
idleWorkers[i] = nil idleWorkers[i] = nil
} }
n++ n++
if n > 0 {
if n >= len(idleWorkers) { if n >= len(idleWorkers) {
p.workers = idleWorkers[:0] p.workers = idleWorkers[:0]
} else { } else {
p.workers = idleWorkers[n:] p.workers = idleWorkers[n:]
} }
}
p.lock.Unlock() p.lock.Unlock()
} }
} }