]> source.dussan.org Git - jquery.git/commitdiff
No ticket: Reduce .find
authorRichard Gibson <richard.gibson@gmail.com>
Sat, 20 Apr 2013 14:02:07 +0000 (10:02 -0400)
committerRichard Gibson <richard.gibson@gmail.com>
Sat, 20 Apr 2013 14:06:31 +0000 (10:06 -0400)
(cherry picked from commit 85b3c82445d9e88c6e747a33ad97f5f9e35a7d35)

src/traversing.js

index a063a4612c906e5206b9733b818bcb484e73fa38..e6b5913e2dd2739b8fb801e50df93709be19a6ab 100644 (file)
@@ -10,13 +10,14 @@ var isSimple = /^.[^:#\[\.,]*$/,
 
 jQuery.fn.extend({
        find: function( selector ) {
-               var self, matched, i,
-                       l = 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 < l; i++ ) {
+                               for ( i = 0; i < len; i++ ) {
                                        if ( jQuery.contains( self[ i ], this ) ) {
                                                return true;
                                        }
@@ -24,15 +25,14 @@ jQuery.fn.extend({
                        }) );
                }
 
-               matched = [];
-               for ( i = 0; i < l; i++ ) {
-                       jQuery.find( selector, this[ i ], matched );
+               for ( i = 0; i < len; i++ ) {
+                       jQuery.find( selector, self[ i ], ret );
                }
 
                // Needed because $( selector, context ) becomes $( context ).find( selector )
-               matched = this.pushStack( l > 1 ? jQuery.unique( matched ) : matched );
-               matched.selector = ( this.selector ? this.selector + " " : "" ) + selector;
-               return matched;
+               ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
+               ret.selector = this.selector ? this.selector + " " + selector : selector;
+               return ret;
        },
 
        has: function( target ) {