From d738161a2ebd6d6494ea5357026fa33884633ae4 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 21 Sep 2020 11:16:33 +0200 Subject: Statistics: only do one hash lookup Signed-off-by: Jason A. Donenfeld --- .../main/java/com/wireguard/android/backend/Statistics.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'tunnel') diff --git a/tunnel/src/main/java/com/wireguard/android/backend/Statistics.java b/tunnel/src/main/java/com/wireguard/android/backend/Statistics.java index 60f78833..c9d51959 100644 --- a/tunnel/src/main/java/com/wireguard/android/backend/Statistics.java +++ b/tunnel/src/main/java/com/wireguard/android/backend/Statistics.java @@ -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 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 rxTx = peerBytes.get(peer); + if (rxTx == null) return 0; - return peerBytes.get(peer).second; + return rxTx.second; } /** -- cgit v1.2.3-59-g8ed1b