From e51be35d84fffbaecf83e4e3afdccbd437af79a1 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Wed, 8 Aug 2018 21:44:01 +0800 Subject: [PATCH] optimization for #7 --- pool.go | 10 ++++------ pool_func.go | 10 ++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/pool.go b/pool.go index 656bf19..2479f3b 100644 --- a/pool.go +++ b/pool.go @@ -77,12 +77,10 @@ func (p *Pool) periodicallyPurge() { idleWorkers[i] = nil } n++ - if n > 0 { - if n >= len(idleWorkers) { - p.workers = idleWorkers[:0] - } else { - p.workers = idleWorkers[n:] - } + if n >= len(idleWorkers) { + p.workers = idleWorkers[:0] + } else { + p.workers = idleWorkers[n:] } p.lock.Unlock() } diff --git a/pool_func.go b/pool_func.go index 0b2eed5..5a3617c 100644 --- a/pool_func.go +++ b/pool_func.go @@ -78,12 +78,10 @@ func (p *PoolWithFunc) periodicallyPurge() { idleWorkers[i] = nil } n++ - if n > 0 { - if n >= len(idleWorkers) { - p.workers = idleWorkers[:0] - } else { - p.workers = idleWorkers[n:] - } + if n >= len(idleWorkers) { + p.workers = idleWorkers[:0] + } else { + p.workers = idleWorkers[n:] } p.lock.Unlock() }