Simplify Utils.merge to use Array.forEach and Array.push for bug 582023.
authorEdward Lee <edilee@mozilla.com>
Thu, 29 Jul 2010 13:02:51 -0700
changeset 50231 39adb0e18d0e6280330e2dc45c34e8aa4a078868
parent 50230 4285a6de57558b9708ab7c35a5214af4fc9cf188
child 50232 2ed5b7a3764af49bf814d5ea2d3efd8544e21757
push id15039
push useredward.lee@engineering.uiuc.edu
push dateThu, 12 Aug 2010 19:47:36 +0000
treeherdermozilla-central@5da28c582cc7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs582023
milestone2.0b3pre
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
Simplify Utils.merge to use Array.forEach and Array.push for bug 582023.
browser/base/content/tabview/modules/utils.js
--- a/browser/base/content/tabview/modules/utils.js
+++ b/browser/base/content/tabview/modules/utils.js
@@ -661,32 +661,19 @@ let Utils = {
         return this.extend([], value);
       return this.extend({}, value);
     }
     return value;
   },
 
   // ----------
   // Function: merge
-  // Merge two arrays and return the result.
+  // Merge two array-like objects into the first and return it.
   merge: function(first, second) {
-    var i = first.length, j = 0;
-
-    if (typeof second.length === "number") {
-      for (let l = second.length; j < l; j++) {
-        first[i++] = second[j];
-      }
-    } else {
-      while (second[j] !== undefined) {
-        first[i++] = second[j++];
-      }
-    }
-
-    first.length = i;
-
+    Array.forEach(second, function(el) Array.push(first, el));
     return first;
   },
 
   // ----------
   // Function: extend
   // Pass several objects in and it will combine them all into the first object and return it.
   extend: function() {
     // copy reference to target object