Author: toad
Date: 2008-03-24 16:50:47 +0000 (Mon, 24 Mar 2008)
New Revision: 18743
Modified:
trunk/freenet/src/freenet/support/SectoredRandomGrabArray.java
Log:
Optimise the common case (1 array only).
Modified: trunk/freenet/src/freenet/support/SectoredRandomGrabArray.java
===================================================================
--- trunk/freenet/src/freenet/support/SectoredRandomGrabArray.java
2008-03-24 16:43:10 UTC (rev 18742)
+++ trunk/freenet/src/freenet/support/SectoredRandomGrabArray.java
2008-03-24 16:50:47 UTC (rev 18743)
@@ -71,6 +71,19 @@
final int MAX_EXCLUDED = 10;
while(true) {
if(grabArrays.length == 0) return null;
+ if(grabArrays.length == 1) {
+ // Optimise the common case
+ RemoveRandomWithObject rga = grabArrays[0];
+ RandomGrabArrayItem item =
rga.removeRandom(excluding);
+ if(rga.isEmpty()) {
+ if(logMINOR)
+ Logger.minor(this, "Removing
only grab array (0) : "+rga+" for "+rga.getObject()+" (is empty)");
+ Object client = rga.getObject();
+ grabArraysByClient.remove(client);
+ grabArrays = new
RemoveRandomWithObject[0];
+ }
+ return item;
+ }
int x = rand.nextInt(grabArrays.length);
RemoveRandomWithObject rga = grabArrays[x];
if(logMINOR)