Rewrote .merge() (faster and less obtuse now). Fixed #5610.

This commit is contained in:
John Resig 2009-12-09 21:43:20 -08:00
parent f25eedf32a
commit 715d1c5a30
2 changed files with 16 additions and 15 deletions

View 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;
},