From: Richard Gibson Date: Sat, 20 Apr 2013 14:02:07 +0000 (-0400) Subject: No ticket: Reduce .find X-Git-Tag: 1.10.0-beta1~16 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=85b3c82445d9e88c6e747a33ad97f5f9e35a7d35;p=jquery.git No ticket: Reduce .find --- diff --git a/src/traversing.js b/src/traversing.js index 8d90d302a..4a274806e 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -10,11 +10,12 @@ var isSimple = /^.[^:#\[\.,]*$/, jQuery.fn.extend({ find: function( selector ) { - var i, ret, self, - len = this.length; + var i, + ret = [], + self = this, + len = self.length; if ( typeof selector !== "string" ) { - self = this; return this.pushStack( jQuery( selector ).filter(function() { for ( i = 0; i < len; i++ ) { if ( jQuery.contains( self[ i ], this ) ) { @@ -24,14 +25,13 @@ jQuery.fn.extend({ }) ); } - ret = []; for ( i = 0; i < len; i++ ) { - jQuery.find( selector, this[ i ], ret ); + jQuery.find( selector, self[ i ], ret ); } // Needed because $( selector, context ) becomes $( context ).find( selector ) ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret ); - ret.selector = ( this.selector ? this.selector + " " : "" ) + selector; + ret.selector = this.selector ? this.selector + " " + selector : selector; return ret; },