Landing some minor perf optimization to jQuery().
This commit is contained in:
parent
0db207da23
commit
b8076a914b
2 changed files with 13 additions and 5 deletions
14
src/core.js
14
src/core.js
|
@ -70,6 +70,14 @@ jQuery.fn = jQuery.prototype = {
|
||||||
return this;
|
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
|
// Handle HTML strings
|
||||||
if ( typeof selector === "string" ) {
|
if ( typeof selector === "string" ) {
|
||||||
// Are we dealing with HTML string or an ID?
|
// Are we dealing with HTML string or an ID?
|
||||||
|
@ -128,6 +136,7 @@ jQuery.fn = jQuery.prototype = {
|
||||||
this.selector = selector;
|
this.selector = selector;
|
||||||
this.context = document;
|
this.context = document;
|
||||||
selector = document.getElementsByTagName( selector );
|
selector = document.getElementsByTagName( selector );
|
||||||
|
return jQuery.merge( this, selector );
|
||||||
|
|
||||||
// HANDLE: $(expr, $(...))
|
// HANDLE: $(expr, $(...))
|
||||||
} else if ( !context || context.jquery ) {
|
} else if ( !context || context.jquery ) {
|
||||||
|
@ -150,9 +159,7 @@ jQuery.fn = jQuery.prototype = {
|
||||||
this.context = selector.context;
|
this.context = selector.context;
|
||||||
}
|
}
|
||||||
|
|
||||||
return jQuery.isArray( selector ) ?
|
return jQuery.makeArray( selector, this );
|
||||||
this.setArray( selector ) :
|
|
||||||
jQuery.makeArray( selector, this );
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Start with an empty selector
|
// Start with an empty selector
|
||||||
|
@ -604,6 +611,7 @@ jQuery.extend({
|
||||||
for ( var l = second.length; j < l; j++ ) {
|
for ( var l = second.length; j < l; j++ ) {
|
||||||
first[ i++ ] = second[ j ];
|
first[ i++ ] = second[ j ];
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
while ( second[j] !== undefined ) {
|
while ( second[j] !== undefined ) {
|
||||||
first[ i++ ] = second[ j++ ];
|
first[ i++ ] = second[ j++ ];
|
||||||
|
|
|
@ -25,7 +25,7 @@ test("jQuery()", function() {
|
||||||
equals( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" );
|
equals( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" );
|
||||||
|
|
||||||
// can actually yield more than one, when iframes are included, the window is an array as well
|
// can actually yield more than one, when iframes are included, the window is an array as well
|
||||||
equals( 1, jQuery(window).length, "Correct number of elements generated for jQuery(window)" );
|
equals( jQuery(window).length, 1, "Correct number of elements generated for jQuery(window)" );
|
||||||
|
|
||||||
|
|
||||||
var main = jQuery("#main");
|
var main = jQuery("#main");
|
||||||
|
|
Loading…
Add table
Reference in a new issue