[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r15023: Try to optimize the browser<->window map cache a bit. (torbutton/trunk/src/components)



Author: mikeperry
Date: 2008-06-08 02:54:00 -0400 (Sun, 08 Jun 2008)
New Revision: 15023

Modified:
   torbutton/trunk/src/components/window-mapper.js
Log:

Try to optimize the browser<->window map cache a bit.



Modified: torbutton/trunk/src/components/window-mapper.js
===================================================================
--- torbutton/trunk/src/components/window-mapper.js	2008-06-08 03:09:59 UTC (rev 15022)
+++ torbutton/trunk/src/components/window-mapper.js	2008-06-08 06:54:00 UTC (rev 15023)
@@ -26,10 +26,9 @@
 
     this.logger = Components.classes["@torproject.org/torbutton-logger;1"]
         .getService(Components.interfaces.nsISupports).wrappedJSObject;
-        
-
-  // This JSObject is exported directly to chrome
-  this.wrappedJSObject = this;
+    this.last_expired = Date.now();
+    // This JSObject is exported directly to chrome
+    this.wrappedJSObject = this;
 }
 
 ContentWindowMapper.prototype =
@@ -82,18 +81,19 @@
   expireOldCache: function() {
       var now = Date.now();
 
+      if((now - this.last_expired) < EXPIRATION_TIME) {
+          this.logger.log(2, "Early check on: "+elem.location);
+          return;
+      }
+
       for(var elem in this.cache) {
           if((now - this.cache[elem].time) > EXPIRATION_TIME) {
               this.logger.log(2, "Deleting cached element: "+elem.location);
               delete this.cache[elem];
           }
       }
-      for(var elem in this.cache) {
-          if((now - this.cache[elem].time) > EXPIRATION_TIME) {
-              this.logger.log(4, "ELEMENT STILL REMAINS: "+elem.location);
-              delete this.cache[elem];
-          }
-      }
+
+      this.last_expired = now;
   },
 
   getBrowserForContentWindow: function(topContentWindow) {