From 50f45a50a757b6b0cf6d94c78083e4911908422e Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Fri, 8 Nov 2013 14:24:06 +0000 Subject: [PATCH] minor optimization --- .../i2p/router/tunnel/pool/BuildExecutor.java | 14 ++++++++------ .../net/i2p/router/tunnel/pool/TunnelPool.java | 16 +++++++++++----- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/router/java/src/net/i2p/router/tunnel/pool/BuildExecutor.java b/router/java/src/net/i2p/router/tunnel/pool/BuildExecutor.java index 41843ca71b..ac3656052b 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/BuildExecutor.java +++ b/router/java/src/net/i2p/router/tunnel/pool/BuildExecutor.java @@ -337,12 +337,14 @@ class BuildExecutor implements Runnable { } } else { if ( (allowed > 0) && (!wanted.isEmpty()) ) { - Collections.shuffle(wanted, _context.random()); - try { - Collections.sort(wanted, new TunnelPoolComparator()); - } catch (IllegalArgumentException iae) { - // Java 7 TimSort - see info in TunnelPoolComparator - continue; + if (wanted.size() > 1) { + Collections.shuffle(wanted, _context.random()); + try { + Collections.sort(wanted, new TunnelPoolComparator()); + } catch (IllegalArgumentException iae) { + // Java 7 TimSort - see info in TunnelPoolComparator + continue; + } } // force the loops to be short, since 3 consecutive tunnel build requests can take diff --git a/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java b/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java index 69a9f6617e..7257ad24f6 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java +++ b/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java @@ -674,11 +674,17 @@ public class TunnelPool { if (rlen > 1 && llen <= 1) return 1; } - byte lhsDelta[] = DataHelper.xor(lhs.getFarEnd().getData(), _base); - byte rhsDelta[] = DataHelper.xor(rhs.getFarEnd().getData(), _base); - int rv = DataHelper.compareTo(lhsDelta, rhsDelta); - if (rv != 0) - return rv; + // TODO don't prefer exact match for security? + byte lhsb[] = lhs.getFarEnd().getData(); + byte rhsb[] = rhs.getFarEnd().getData(); + for (int i = 0; i < _base.length; i++) { + int ld = (lhsb[i] ^ _base[i]) & 0xff; + int rd = (rhsb[i] ^ _base[i]) & 0xff; + if (ld < rd) + return -1; + if (ld > rd) + return 1; + } // latest-expiring first as a tie-breaker return (int) (rhs.getExpiration() - lhs.getExpiration()); } -- GitLab