Skip to content

Commit

Permalink
optimize:reduce loop (#1532)
Browse files Browse the repository at this point in the history
  • Loading branch information
tylitianrui committed Mar 28, 2023
1 parent 0be5a41 commit 5209cc3
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lbclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 5209cc3

Please sign in to comment.