Bug 800275 - Decreasing assymptoptic complexity of two loops from n^2 to n by removing the Array#shift usage, r=jaws
authorNanci Bonfim <nancibonfim@gmail.com>
Wed, 17 Oct 2012 22:01:23 -0300
changeset 110703 8f94888f5fdec96bc8a65062d46b6c191fcad6ee
parent 110702 142ee4ac9b309370b5f539e80a91327fc1236d54
child 110704 49138b4f5fc92cbc103efe706e9fd913a8386d1b
push id23708
push userryanvm@gmail.com
push dateFri, 19 Oct 2012 01:28:59 +0000
treeherdermozilla-central@fd5556088388 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs800275
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 800275 - Decreasing assymptoptic complexity of two loops from n^2 to n by removing the Array#shift usage, r=jaws
toolkit/components/social/FrameWorker.jsm
--- a/toolkit/components/social/FrameWorker.jsm
+++ b/toolkit/components/social/FrameWorker.jsm
@@ -1,9 +1,9 @@
-/* -*- Mode: JavaScript; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
 /*
  * This is an implementation of a "Shared Worker" using an iframe in the
@@ -210,29 +210,27 @@ FrameWorker.prototype = {
         Cu.reportError("FrameWorker: Error evaluating worker script for " + worker.name + ": " + e + "; " +
             (e.lineNumber ? ("Line #" + e.lineNumber) : "") +
             (e.stack ? ("\n" + e.stack) : ""));
         return;
       }
 
       // so finally we are ready to roll - dequeue all the pending connects
       worker.loaded = true;
-
-      let pending = worker.pendingPorts;
-      while (pending.length) {
-        let port = pending.shift();
+      for (let port of worker.pendingPorts) {
         if (port._portid) { // may have already been closed!
           try {
             port._createWorkerAndEntangle(worker);
           }
           catch(e) {
             Cu.reportError("FrameWorker: Failed to create worker port: " + e + "\n" + e.stack);
           }
         }
       }
+      worker.pendingPorts = [];
     });
 
     // the 'unload' listener cleans up the worker and the sandbox.  This
     // will be triggered via either our 'terminate' function or by the
     // window unloading as part of shutdown.
     workerWindow.addEventListener("unload", function unloadListener() {
       workerWindow.removeEventListener("unload", unloadListener);
       delete workerCache[worker.url];
@@ -414,19 +412,20 @@ ClientPort.prototype = {
     }
     return JSON.parse(data);
   },
 
   _createWorkerAndEntangle: function fw_ClientPort_createWorkerAndEntangle(worker) {
     this._window = worker.frame.contentWindow;
     worker.ports[this._portid] = this;
     this._postControlMessage("port-create");
-    while (this._pendingMessagesOutgoing.length) {
-      this._dopost(this._pendingMessagesOutgoing.shift());
+    for (let message of this._pendingMessagesOutgoing) {
+      this._dopost(message);
     }
+    this._pendingMessagesOutgoing = [];
   },
 
   _dopost: function fw_ClientPort_dopost(data) {
     if (!this._window) {
       this._pendingMessagesOutgoing.push(data);
     } else {
       this._window.postMessage(data, "*");
     }