Author: toad
Date: 2008-07-04 13:46:58 +0000 (Fri, 04 Jul 2008)
New Revision: 20986

Modified:
   
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
Log:
Only check whether the key is in pendingKeys on every 16th element.
Access to pendingKeys is *expensive*.

Modified: 
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
===================================================================
--- 
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java  
    2008-07-04 13:45:07 UTC (rev 20985)
+++ 
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java  
    2008-07-04 13:46:58 UTC (rev 20986)
@@ -244,6 +244,8 @@
                return maybeMakeChosenRequest(req, container, context);
        }

+       private int ctr;
+       
        public ChosenRequest maybeMakeChosenRequest(SendableRequest req, 
ObjectContainer container, ClientContext context) {
                if(req == null) return null;
                if(req.isEmpty(container) || req.isCancelled(container)) return 
null;
@@ -272,8 +274,11 @@
                                container.set(ret);
                                if(logMINOR)
                                        Logger.minor(this, "Storing "+ret+" for 
"+req);
-                               if((req instanceof SendableGet) && 
!inPendingKeys(req, key)) {
-                                       Logger.error(this, "Selected key not in 
pendingKeys: key "+key+" for "+req);
+                               if((ctr++ & 15) == 0) {
+                                       // This check is quite expensive, don't 
do it all the time.
+                                       if((req instanceof SendableGet) && 
!inPendingKeys(req, key)) {
+                                               Logger.error(this, "Selected 
key not in pendingKeys: key "+key+" for "+req);
+                                       }
                                }
                        } else {
                                ret = new ChosenRequest(req, token, key, ckey, 
req.getPriorityClass(container));


Reply via email to