1
0
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:
superkinglabs
2018-03-14 16:12:51 +05:30
committed by Vladimir Mihailenco
parent 17b6cf1e5a
commit 877867d284
2 changed files with 62 additions and 36 deletions

View File

@@ -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
}