mirror of
https://github.com/redis/go-redis.git
synced 2025-08-07 12:42:55 +03:00
Remove costly 'appendIfNotExists' and 'remove' call from PubSub (#743)
* remove costly 'appendIfNotExists' and 'remove' call from pubsub
This commit is contained in:
committed by
Vladimir Mihailenco
parent
17b6cf1e5a
commit
877867d284
28
cluster.go
28
cluster.go
@@ -1409,3 +1409,31 @@ func appendNode(nodes []*clusterNode, node *clusterNode) []*clusterNode {
|
||||
}
|
||||
return append(nodes, node)
|
||||
}
|
||||
|
||||
func appendIfNotExists(ss []string, es ...string) []string {
|
||||
loop:
|
||||
for _, e := range es {
|
||||
for _, s := range ss {
|
||||
if s == e {
|
||||
continue loop
|
||||
}
|
||||
}
|
||||
ss = append(ss, e)
|
||||
}
|
||||
return ss
|
||||
}
|
||||
|
||||
func remove(ss []string, es ...string) []string {
|
||||
if len(es) == 0 {
|
||||
return ss[:0]
|
||||
}
|
||||
for _, e := range es {
|
||||
for i, s := range ss {
|
||||
if s == e {
|
||||
ss = append(ss[:i], ss[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return ss
|
||||
}
|
||||
|
Reference in New Issue
Block a user