Skip to content
Permalink
Browse files

Avoid running jQuery.unique() for methods that are guaranteed to prod…

…uce a unique result set. Fixes #7964 - Some traversal methods perform an unnecessary uniqueness check.
  • Loading branch information...
scottgonzalez committed Jan 14, 2011
1 parent a8fa5f2 commit e5ee89ec9a11804b39e9722f47eeeb00648f37ea
Showing with 9 additions and 2 deletions.
  1. +9 −2 src/traversing.js
@@ -6,7 +6,14 @@ var runtil = /Until$/,
rmultiselector = /,/,
isSimple = /^.[^:#\[\.,]*$/,
slice = Array.prototype.slice,
POS = jQuery.expr.match.POS;
POS = jQuery.expr.match.POS,
// methods guaranteed to produce a unique set when starting from a unique set
guaranteedUnique = {
children: true,
contents: true,
next: true,
prev: true
};

jQuery.fn.extend({
find: function( selector ) {
@@ -206,7 +213,7 @@ jQuery.each({
ret = jQuery.filter( selector, ret );
}

ret = this.length > 1 ? jQuery.unique( ret ) : ret;
ret = this.length > 1 && !guaranteedUnique[ name ] ? jQuery.unique( ret ) : ret;

if ( (this.length > 1 || rmultiselector.test( selector )) && rparentsprev.test( name ) ) {
ret = ret.reverse();

0 comments on commit e5ee89e

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