diff options
author | jeresig <jeresig@gmail.com> | 2010-01-28 17:17:51 -0500 |
---|---|---|
committer | jeresig <jeresig@gmail.com> | 2010-01-28 17:17:51 -0500 |
commit | b8076a914ba9d400dc9c48d866b145df6fabafcf (patch) | |
tree | 92f01020d1cd816630686dcc269add95191f4251 /src | |
parent | 0db207da238e879dad20f68178e6248750d3b984 (diff) | |
download | jquery-b8076a914ba9d400dc9c48d866b145df6fabafcf.tar.gz jquery-b8076a914ba9d400dc9c48d866b145df6fabafcf.zip |
Landing some minor perf optimization to jQuery().
Diffstat (limited to 'src')
-rw-r--r-- | src/core.js | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/core.js b/src/core.js index 81b48318c..2271ceb53 100644 --- a/src/core.js +++ b/src/core.js @@ -69,6 +69,14 @@ jQuery.fn = jQuery.prototype = { this.length = 1; return this; } + + // The body element only exists once, optimize finding it + if ( selector === "body" && !context ) { + this.context = this[0] = document.body; + this.selector = "body"; + this.length = 1; + return this; + } // Handle HTML strings if ( typeof selector === "string" ) { @@ -99,7 +107,7 @@ jQuery.fn = jQuery.prototype = { ret = buildFragment( [ match[1] ], [ doc ] ); selector = (ret.cacheable ? ret.fragment.cloneNode(true) : ret.fragment).childNodes; } - + return jQuery.merge( this, selector ); // HANDLE: $("#id") @@ -128,6 +136,7 @@ jQuery.fn = jQuery.prototype = { this.selector = selector; this.context = document; selector = document.getElementsByTagName( selector ); + return jQuery.merge( this, selector ); // HANDLE: $(expr, $(...)) } else if ( !context || context.jquery ) { @@ -150,9 +159,7 @@ jQuery.fn = jQuery.prototype = { this.context = selector.context; } - return jQuery.isArray( selector ) ? - this.setArray( selector ) : - jQuery.makeArray( selector, this ); + return jQuery.makeArray( selector, this ); }, // Start with an empty selector @@ -604,6 +611,7 @@ jQuery.extend({ for ( var l = second.length; j < l; j++ ) { first[ i++ ] = second[ j ]; } + } else { while ( second[j] !== undefined ) { first[ i++ ] = second[ j++ ]; |