forked from TrueCloudLab/neoneo-go
network: microoptimize iteratePeersWithSendMsg()
Now that s.getPeers() returns a slice we can use slice for `success` too, maps are more expensive.
This commit is contained in:
parent
d51db20405
commit
de6f4987f6
1 changed files with 5 additions and 6 deletions
|
@ -1154,12 +1154,11 @@ func (s *Server) iteratePeersWithSendMsg(msg *Message, send func(Peer, bool, []b
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
success := make(map[Peer]bool, len(peers))
|
success := make([]bool, len(peers))
|
||||||
okCount := 0
|
okCount := 0
|
||||||
sentCount := 0
|
sentCount := 0
|
||||||
for _, peer := range peers {
|
for i, peer := range peers {
|
||||||
if peerOK != nil && !peerOK(peer) {
|
if peerOK != nil && !peerOK(peer) {
|
||||||
success[peer] = false
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
okCount++
|
okCount++
|
||||||
|
@ -1169,7 +1168,7 @@ func (s *Server) iteratePeersWithSendMsg(msg *Message, send func(Peer, bool, []b
|
||||||
if msg.Command == CMDGetAddr {
|
if msg.Command == CMDGetAddr {
|
||||||
peer.AddGetAddrSent()
|
peer.AddGetAddrSent()
|
||||||
}
|
}
|
||||||
success[peer] = true
|
success[i] = true
|
||||||
sentCount++
|
sentCount++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1179,8 +1178,8 @@ func (s *Server) iteratePeersWithSendMsg(msg *Message, send func(Peer, bool, []b
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform blocking send now.
|
// Perform blocking send now.
|
||||||
for _, peer := range peers {
|
for i, peer := range peers {
|
||||||
if _, ok := success[peer]; ok || peerOK != nil && !peerOK(peer) {
|
if success[i] || (peerOK != nil && !peerOK(peer)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := send(peer, true, pkt); err != nil {
|
if err := send(peer, true, pkt); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue