Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 3992780
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
20 changes: 19 additions & 1 deletion actor/pidset.go
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}
6 changes: 1 addition & 5 deletions router/broadcast_router.go
Expand Up @@ -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{}) {
Expand Down

0 comments on commit 3992780

Please sign in to comment.