I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 50f45a50 authored by zzz's avatar zzz
Browse files

minor optimization

parent 6b326c37
No related branches found
No related tags found
No related merge requests found
...@@ -337,12 +337,14 @@ class BuildExecutor implements Runnable { ...@@ -337,12 +337,14 @@ class BuildExecutor implements Runnable {
} }
} else { } else {
if ( (allowed > 0) && (!wanted.isEmpty()) ) { if ( (allowed > 0) && (!wanted.isEmpty()) ) {
Collections.shuffle(wanted, _context.random()); if (wanted.size() > 1) {
try { Collections.shuffle(wanted, _context.random());
Collections.sort(wanted, new TunnelPoolComparator()); try {
} catch (IllegalArgumentException iae) { Collections.sort(wanted, new TunnelPoolComparator());
// Java 7 TimSort - see info in TunnelPoolComparator } catch (IllegalArgumentException iae) {
continue; // Java 7 TimSort - see info in TunnelPoolComparator
continue;
}
} }
// force the loops to be short, since 3 consecutive tunnel build requests can take // force the loops to be short, since 3 consecutive tunnel build requests can take
......
...@@ -674,11 +674,17 @@ public class TunnelPool { ...@@ -674,11 +674,17 @@ public class TunnelPool {
if (rlen > 1 && llen <= 1) if (rlen > 1 && llen <= 1)
return 1; return 1;
} }
byte lhsDelta[] = DataHelper.xor(lhs.getFarEnd().getData(), _base); // TODO don't prefer exact match for security?
byte rhsDelta[] = DataHelper.xor(rhs.getFarEnd().getData(), _base); byte lhsb[] = lhs.getFarEnd().getData();
int rv = DataHelper.compareTo(lhsDelta, rhsDelta); byte rhsb[] = rhs.getFarEnd().getData();
if (rv != 0) for (int i = 0; i < _base.length; i++) {
return rv; 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 // latest-expiring first as a tie-breaker
return (int) (rhs.getExpiration() - lhs.getExpiration()); return (int) (rhs.getExpiration() - lhs.getExpiration());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment