Skip to content
Permalink
Browse files

Removed the need for the results set to have array methods. Resolves …

…jQuery bug #4250.
  • Loading branch information...
jeresig committed Feb 25, 2009
1 parent f094c80 commit 58235cc38ea835cde0ae90dd2919b86e47f3dd05
Showing with 13 additions and 15 deletions.
  1. +3 −8 src/core.js
  2. +10 −7 src/selector.js
@@ -279,14 +279,9 @@ jQuery.fn = jQuery.prototype = {
return this.prevObject || jQuery(null);
},

// For internal use only.
// Behaves like an Array's method, not like a jQuery method.
push: [].push,
sort: [].sort,
splice: [].splice,

find: function( selector ) {
var ret = this.pushStack( "", "find", selector ), length = 0;
var ret = this.pushStack( "", "find", selector ), length = 0,
splice = Array.prototype.splice;

for ( var i = 0, l = this.length; i < l; i++ ) {
length = ret.length;
@@ -297,7 +292,7 @@ jQuery.fn = jQuery.prototype = {
for ( var n = length; n < ret.length; n++ ) {
for ( var r = 0; r < length; r++ ) {
if ( ret[r] === ret[n] ) {
ret.splice(n--, 1);
splice.call(ret, n--, 1);
break;
}
}
@@ -8,7 +8,10 @@

var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?/g,
done = 0,
toString = Object.prototype.toString;
toString = Object.prototype.toString,
arraySplice = Array.prototype.splice,
arrayPush = Array.prototype.push,
arraySort = Array.prototype.sort;

var Sizzle = function(selector, context, results, seed) {
results = results || [];
@@ -104,17 +107,17 @@ var Sizzle = function(selector, context, results, seed) {

if ( toString.call(checkSet) === "[object Array]" ) {
if ( !prune ) {
results.push.apply( results, checkSet );
arrayPush.apply( results, checkSet );
} else if ( context && context.nodeType === 1 ) {
for ( var i = 0; checkSet[i] != null; i++ ) {
if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && contains(context, checkSet[i])) ) {
results.push( set[i] );
arrayPush.call( results, set[i] );
}
}
} else {
for ( var i = 0; checkSet[i] != null; i++ ) {
if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
results.push( set[i] );
arrayPush.call( results, set[i] );
}
}
}
@@ -133,12 +136,12 @@ var Sizzle = function(selector, context, results, seed) {
Sizzle.uniqueSort = function(results){
if ( sortOrder ) {
hasDuplicate = false;
results.sort(sortOrder);
arraySort.call(results, sortOrder);

if ( hasDuplicate ) {
for ( var i = 1; i < results.length; i++ ) {
if ( results[i] === results[i-1] ) {
results.splice(i--, 1);
arraySplice.call(results, i--, 1);
}
}
}
@@ -663,7 +666,7 @@ var makeArray = function(array, results) {
array = Array.prototype.slice.call( array );

if ( results ) {
results.push.apply( results, array );
arrayPush.apply( results, array );
return results;
}

0 comments on commit 58235cc

Please sign in to comment.
You can’t perform that action at this time.