Author: toad
Date: 2008-03-24 17:05:28 +0000 (Mon, 24 Mar 2008)
New Revision: 18745

Modified:
   trunk/freenet/src/freenet/support/SectoredRandomGrabArray.java
Log:
Optimise some more simple common cases.

Modified: trunk/freenet/src/freenet/support/SectoredRandomGrabArray.java
===================================================================
--- trunk/freenet/src/freenet/support/SectoredRandomGrabArray.java      
2008-03-24 16:56:39 UTC (rev 18744)
+++ trunk/freenet/src/freenet/support/SectoredRandomGrabArray.java      
2008-03-24 17:05:28 UTC (rev 18745)
@@ -84,6 +84,27 @@
                                }
                                return item;
                        }
+                       if(grabArrays.length == 2) {
+                               // Another simple common case
+                               int x = rand.nextBoolean() ? 1 : 0;
+                               RemoveRandomWithObject rga = grabArrays[x];
+                               RemoveRandomWithObject firstRGA = rga;
+                               RandomGrabArrayItem item = 
rga.removeRandom(excluding);
+                               if(item == null) {
+                                       x = 1-x;
+                                       rga = grabArrays[x];
+                                       item = rga.removeRandom(excluding);
+                                       if(firstRGA.isEmpty() && rga.isEmpty()) 
{
+                                               
grabArraysByClient.remove(rga.getObject());
+                                               
grabArraysByClient.remove(firstRGA.getObject());
+                                               grabArrays = new 
RemoveRandomWithObject[0];
+                                       } else if(firstRGA.isEmpty()) {
+                                               
grabArraysByClient.remove(firstRGA.getObject());
+                                               grabArrays = new 
RemoveRandomWithObject[] { firstRGA };
+                                       }
+                                       return item;
+                               } else return item;
+                       }
                        int x = rand.nextInt(grabArrays.length);
                        RemoveRandomWithObject rga = grabArrays[x];
                        if(logMINOR)
@@ -112,7 +133,7 @@
                                        // Hmmm...
                                        excluded++;
                                        if(excluded > MAX_EXCLUDED) {
-                                               Logger.error(this, "Too many 
sub-arrays are entirely excluded on "+this, new Exception("error"));
+                                               Logger.error(this, "Too many 
sub-arrays are entirely excluded on "+this+" length = "+grabArrays.length, new 
Exception("error"));
                                                return null;
                                        }
                                }


Reply via email to