aboutsummaryrefslogtreecommitdiff
path: root/lbclient.go
diff options
context:
space:
mode:
authorGravatar tyltr <tylitianrui@126.com> 2023-03-28 11:49:25 +0800
committerGravatar GitHub <noreply@github.com> 2023-03-28 05:49:25 +0200
commit5209cc307786698c4b509018769539ae3a2e12be (patch)
tree4bcadc6b00ea921e7c2f23af52b1e0ebcde593db /lbclient.go
parenttest: simplify bytes.Buffer declaration (#1523) (diff)
downloadfasthttp-5209cc307786698c4b509018769539ae3a2e12be.tar.gz
fasthttp-5209cc307786698c4b509018769539ae3a2e12be.tar.bz2
fasthttp-5209cc307786698c4b509018769539ae3a2e12be.zip
optimize:reduce loop (#1532)
Diffstat (limited to 'lbclient.go')
-rw-r--r--lbclient.go6
1 files changed, 2 insertions, 4 deletions
diff --git a/lbclient.go b/lbclient.go
index bc0b63c..56ac1bf 100644
--- a/lbclient.go
+++ b/lbclient.go
@@ -112,16 +112,14 @@ func (cc *LBClient) AddClient(c BalancingClient) int {
func (cc *LBClient) RemoveClients(rc func(BalancingClient) bool) int {
cc.mu.Lock()
n := 0
- for _, cs := range cc.cs {
+ for idx, cs := range cc.cs {
+ cc.cs[idx] = nil
if rc(cs.c) {
continue
}
cc.cs[n] = cs
n++
}
- for i := n; i < len(cc.cs); i++ {
- cc.cs[i] = nil
- }
cc.cs = cc.cs[:n]
cc.mu.Unlock()