Skip to content

Commit 5209cc3

Browse files
authored
optimize:reduce loop (#1532)
1 parent 0be5a41 commit 5209cc3

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

lbclient.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,14 @@ func (cc *LBClient) AddClient(c BalancingClient) int {
112112
func (cc *LBClient) RemoveClients(rc func(BalancingClient) bool) int {
113113
cc.mu.Lock()
114114
n := 0
115-
for _, cs := range cc.cs {
115+
for idx, cs := range cc.cs {
116+
cc.cs[idx] = nil
116117
if rc(cs.c) {
117118
continue
118119
}
119120
cc.cs[n] = cs
120121
n++
121122
}
122-
for i := n; i < len(cc.cs); i++ {
123-
cc.cs[i] = nil
124-
}
125123
cc.cs = cc.cs[:n]
126124

127125
cc.mu.Unlock()

0 commit comments

Comments
 (0)