Skip to content
Permalink
Browse files

Merge pull request #232 from PotterDai/pidset-clone

Add PIDSet.Clone for better performance.
  • Loading branch information...
PotterDai committed Apr 11, 2018
2 parents 83fec9a + 32ebdfc commit 3992780c0af683deb5ec3746f4ec5845139c6e42
Showing with 20 additions and 6 deletions.
  1. +19 −1 actor/pidset.go
  2. +1 −5 router/broadcast_router.go
@@ -17,8 +17,9 @@ func NewPIDSet(pids ...*PID) *PIDSet {
}

func (p *PIDSet) indexOf(v *PID) int {
key := v.key()
for i, pid := range p.s {
if v.key() == pid {
if key == pid {
return i
}
}
@@ -141,3 +142,20 @@ func (p *PIDSet) ForEach(f func(i int, pid PID)) {
}
}
}

func (p *PIDSet) Clone() *PIDSet {
var s PIDSet
if p.s != nil {
s.s = make([]string, len(p.s))
for i, v := range p.s {
s.s[i] = v
}
}
if p.m != nil {
s.m = make(map[string]struct{}, len(p.m))
for v := range p.m {
s.m[v] = struct{}{}
}
}
return &s
}
@@ -25,11 +25,7 @@ func (state *broadcastRouterState) SetRoutees(routees *actor.PIDSet) {
}

func (state *broadcastRouterState) GetRoutees() *actor.PIDSet {
newSet := &actor.PIDSet{}
state.routees.ForEach(func(i int, pid actor.PID) {
newSet.Add(&pid)
})
return newSet
return state.routees.Clone()
}

func (state *broadcastRouterState) RouteMessage(message interface{}) {

0 comments on commit 3992780

Please sign in to comment.
You can’t perform that action at this time.