Rewrote .merge() (faster and less obtuse now). Fixed #5610.
[jquery.git] / src / core.js
index 5f1bc3a..4c7b07e 100644 (file)
@@ -567,23 +567,20 @@ jQuery.extend({
        },
 
        merge: function( first, second ) {
-               var pos, i = second.length;
+               var i = first.length, j = 0;
 
-               // We have to get length this way when IE & Opera overwrite the length
-               // expando of getElementsByTagName
-               if ( i && i.nodeType ) {
-                       for ( i = 0; second[i]; ++i ) {}
-               }
-               
-               pos = i + first.length;
-               
-               // Correct length for non Arrays
-               first.length = pos;
-               
-               while ( i ) {
-                       first[ --pos ] = second[ --i ];
+               if ( typeof second.length === "number" ) {
+                       for ( var l = second.length; j < l; j++ ) {
+                               first[ i++ ] = second[ j ];
+                       }
+               } else {
+                       while ( second[j] !== undefined ) {
+                               first[ i++ ] = second[ j++ ];
+                       }
                }
 
+               first.length = i;
+
                return first;
        },