]> source.dussan.org Git - jquery.git/commitdiff
Fix #13349. No need to sort simple .find() cases.
authorDave Methvin <dave.methvin@gmail.com>
Wed, 30 Jan 2013 01:57:26 +0000 (20:57 -0500)
committerDave Methvin <dave.methvin@gmail.com>
Wed, 30 Jan 2013 01:58:26 +0000 (20:58 -0500)
src/traversing.js

index 99c38101002e4f49bd3c5bfe0fba1aa9dd900a56..8d8b9930f744f875b885a129142710d5683c5046 100644 (file)
@@ -12,12 +12,13 @@ var runtil = /Until$/,
 
 jQuery.fn.extend({
        find: function( selector ) {
-               var i, ret, self;
+               var i, ret, self,
+                       len = this.length;
 
                if ( typeof selector !== "string" ) {
                        self = this;
                        return this.pushStack( jQuery( selector ).filter(function() {
-                               for ( i = 0; i < self.length; i++ ) {
+                               for ( i = 0; i < len; i++ ) {
                                        if ( jQuery.contains( self[ i ], this ) ) {
                                                return true;
                                        }
@@ -26,12 +27,12 @@ jQuery.fn.extend({
                }
 
                ret = [];
-               for ( i = 0; i < this.length; i++ ) {
+               for ( i = 0; i < len; i++ ) {
                        jQuery.find( selector, this[ i ], ret );
                }
 
                // Needed because $( selector, context ) becomes $( context ).find( selector )
-               ret = this.pushStack( jQuery.unique( ret ) );
+               ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
                ret.selector = ( this.selector ? this.selector + " " : "" ) + selector;
                return ret;
        },