Statistics: only do one hash lookup

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2020-09-21 11:16:33 +02:00
parent 52c2e9cd24
commit d738161a2e

View File

@ -56,9 +56,10 @@ public class Statistics {
* @return a long representing the number of bytes received by this peer.
*/
public long peerRx(final Key peer) {
if (!peerBytes.containsKey(peer))
final Pair<Long, Long> rxTx = peerBytes.get(peer);
if (rxTx == null)
return 0;
return peerBytes.get(peer).first;
return rxTx.first;
}
/**
@ -69,9 +70,10 @@ public class Statistics {
* @return a long representing the number of bytes transmitted by this peer.
*/
public long peerTx(final Key peer) {
if (!peerBytes.containsKey(peer))
final Pair<Long, Long> rxTx = peerBytes.get(peer);
if (rxTx == null)
return 0;
return peerBytes.get(peer).second;
return rxTx.second;
}
/**