From 535c04481e94d73b8d2731eb920390af5dda0f86 Mon Sep 17 00:00:00 2001 From: vyzo Date: Sun, 8 Mar 2020 17:22:16 +0200 Subject: [PATCH] minimize hash table accesses --- score.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/score.go b/score.go index 33823b7..b5e03c7 100644 --- a/score.go +++ b/score.go @@ -445,18 +445,20 @@ func (ps *peerScore) markFirstMessageDelivery(p peer.ID, msg *Message) { continue } + cap := ps.params.Topics[topic].FirstMessageDeliveriesCap tstats.firstMessageDeliveries += 1 - if tstats.firstMessageDeliveries > ps.params.Topics[topic].FirstMessageDeliveriesCap { - tstats.firstMessageDeliveries = ps.params.Topics[topic].FirstMessageDeliveriesCap + if tstats.firstMessageDeliveries > cap { + tstats.firstMessageDeliveries = cap } if !tstats.inMesh { continue } + cap = ps.params.Topics[topic].MeshMessageDeliveriesCap tstats.meshMessageDeliveries += 1 - if tstats.meshMessageDeliveries > ps.params.Topics[topic].MeshMessageDeliveriesCap { - tstats.meshMessageDeliveries = ps.params.Topics[topic].MeshMessageDeliveriesCap + if tstats.meshMessageDeliveries > cap { + tstats.meshMessageDeliveries = cap } } } @@ -482,9 +484,10 @@ func (ps *peerScore) markDuplicateMessageDelivery(p peer.ID, msg *Message, first continue } + cap := ps.params.Topics[topic].MeshMessageDeliveriesCap tstats.meshMessageDeliveries += 1 - if tstats.meshMessageDeliveries > ps.params.Topics[topic].MeshMessageDeliveriesCap { - tstats.meshMessageDeliveries = ps.params.Topics[topic].MeshMessageDeliveriesCap + if tstats.meshMessageDeliveries > cap { + tstats.meshMessageDeliveries = cap } } }