Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[1.8.2] Fix #12229: size/consistency improvements #887

Closed
wants to merge 6 commits into from

5 participants

Richard Gibson Dave Methvin Rick Waldron Julian Aubourg Timo Tijhof
Richard Gibson
Collaborator

Slightly smaller size, but still smaller.

Sizes - compared to master @ 1d8bf0a

    258442       (-52)  dist/jquery.js                                         
     92532       (-28)  dist/jquery.min.js                                     
     33084       (-21)  dist/jquery.min.js.gz
Dave Methvin

"Please use with caution" ==> "Some incredibly common plugin probably uses this without asking and will break horribly when we remove it."

Can we save that pain for 1.9? I'd feel bad doing this in a minor-point release, even on an undocumented property. We can still switch to guid for everything internally.

Dave Methvin

Neither is a great example of clear code, but I can stumble through the old code better than the new. I have to admit it's a clever way to do it though.

Richard Gibson
Collaborator

Good points as usual, @dmethvin.

Richard Gibson
Collaborator

@dmethvin Can we get this in 1.8.2? I'd like a nice base for the hackathon.

Dave Methvin
Owner

Was just working on this, yeah.

Rick Waldron rwaldron commented on the diff
src/data.js
@@ -232,7 +232,7 @@ jQuery.fn.extend({
for ( l = attr.length; i < l; i++ ) {
name = attr[i].name;
- if ( name.indexOf( "data-" ) === 0 ) {
+ if ( !name.indexOf( "data-" ) ) {
Rick Waldron Collaborator

Being explicit is faster then coercion, I suspect that extend is a perf sensitive operation...

Dave Methvin Owner

I don't think it's in a path that hot; this particular code only runs once to pull in the data attrs.

Rick Waldron Collaborator

it's a nested loop...?

Julian Aubourg Collaborator

I love hot paths.

Rick Waldron Collaborator

I love hot pants

Rick Waldron Collaborator

I'd like to call a friend on this one... my eyes tricked me into thinking this was deeper then it is.

Day 1 of TC39 + trying to look at PRs. Whoops!

Dave Methvin Owner

NP, just wanted to be sure I didn't miss something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Dave Methvin dmethvin commented on the diff
src/data.js
@@ -58,7 +58,7 @@ jQuery.extend({
// Only DOM nodes need a new unique ID for each element since their data
// ends up in the global cache
if ( isNode ) {
- elem[ internalKey ] = id = jQuery.deletedIds.pop() || ++jQuery.uuid;
+ elem[ internalKey ] = id = jQuery.deletedIds.pop() || jQuery.guid++;
Dave Methvin Owner

Clearly you haven't read http://bugs.jquery.com/ticket/12365 !

Julian Aubourg Collaborator

+1 dmethvin!

Rick Waldron Collaborator

<3

Richard Gibson Collaborator

LOL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Dave Methvin dmethvin closed this in 15b5dbf
Dave Methvin
Owner

I liked all the changes, just spent some time trying to convince myself they were all truly innocuous since we're closed to 1.8.2.

Timo Tijhof

How does that save bytes, its the same byte count? Or do you mean through sampleability through gzip?

Collaborator

Exactly. We try to gzip as small as possible.

Mescoda mescoda referenced this pull request from a commit in mescoda/jquery
Richard Gibson gibson042 Fix #12229, size/consistency improvements. Close gh-887. 7520927
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
19 src/ajax.js
View
@@ -1,7 +1,7 @@
-var // Document location
- ajaxLocation,
- // Document location segments
+var
+ // Document location
ajaxLocParts,
+ ajaxLocation,
rhash = /#.*$/,
rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg, // IE leaves an \r character at EOL
@@ -518,7 +518,7 @@ jQuery.extend({
// Set data for the fake xhr object
jqXHR.status = status;
- jqXHR.statusText = "" + ( nativeStatusText || statusText );
+ jqXHR.statusText = ( nativeStatusText || statusText ) + "";
// Success/Error
if ( isSuccess ) {
@@ -578,14 +578,11 @@ jQuery.extend({
// Extract dataTypes list
s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().split( core_rspace );
- // Determine if a cross-domain request is in order
+ // A cross-domain request is in order when we have a protocol:host:port mismatch
if ( s.crossDomain == null ) {
- parts = rurl.exec( s.url.toLowerCase() );
- s.crossDomain = !!( parts &&
- ( parts[ 1 ] != ajaxLocParts[ 1 ] || parts[ 2 ] != ajaxLocParts[ 2 ] ||
- ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? 80 : 443 ) ) !=
- ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? 80 : 443 ) ) )
- );
+ parts = rurl.exec( s.url.toLowerCase() ) || false;
+ s.crossDomain = parts && ( parts.join(":") + ( parts[ 3 ] ? "" : parts[ 1 ] === "http:" ? 80 : 443 ) ) !==
+ ( ajaxLocParts.join(":") + ( ajaxLocParts[ 3 ] ? "" : ajaxLocParts[ 1 ] === "http:" ? 80 : 443 ) );
}
// Convert data if not already a string
10 src/attributes.js
View
@@ -57,7 +57,7 @@ jQuery.fn.extend({
setClass = " " + elem.className + " ";
for ( c = 0, cl = classNames.length; c < cl; c++ ) {
- if ( !~setClass.indexOf( " " + classNames[ c ] + " " ) ) {
+ if ( setClass.indexOf( " " + classNames[ c ] + " " ) < 0 ) {
setClass += classNames[ c ] + " ";
}
}
@@ -90,7 +90,7 @@ jQuery.fn.extend({
// loop over each item in the removal list
for ( c = 0, cl = removes.length; c < cl; c++ ) {
// Remove until there is nothing to remove,
- while ( className.indexOf(" " + removes[ c ] + " ") > -1 ) {
+ while ( className.indexOf(" " + removes[ c ] + " ") >= 0 ) {
className = className.replace( " " + removes[ c ] + " " , " " );
}
}
@@ -144,7 +144,7 @@ jQuery.fn.extend({
i = 0,
l = this.length;
for ( ; i < l; i++ ) {
- if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) > -1 ) {
+ if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) {
return true;
}
}
@@ -322,7 +322,7 @@ jQuery.extend({
return ret;
} else {
- elem.setAttribute( name, "" + value );
+ elem.setAttribute( name, value + "" );
return value;
}
@@ -586,7 +586,7 @@ if ( !jQuery.support.style ) {
return elem.style.cssText.toLowerCase() || undefined;
},
set: function( elem, value ) {
- return ( elem.style.cssText = "" + value );
+ return ( elem.style.cssText = value + "" );
}
};
}
6 src/core.js
View
@@ -559,7 +559,7 @@ jQuery.extend({
},
nodeName: function( elem, name ) {
- return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase();
+ return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
},
// args is for internal usage only
@@ -616,7 +616,7 @@ jQuery.extend({
function( text ) {
return text == null ?
"" :
- text.toString().replace( rtrim, "" );
+ ( text + "" ).replace( rtrim, "" );
},
// results is for internal usage only
@@ -762,7 +762,7 @@ jQuery.extend({
};
// Set the guid of unique handler to the same of original handler, so it can be removed
- proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++;
+ proxy.guid = fn.guid = fn.guid || jQuery.guid++;
return proxy;
},
6 src/data.js
View
@@ -6,7 +6,7 @@ jQuery.extend({
deletedIds: [],
- // Please use with caution
+ // Remove at next major release (1.9/2.0)
uuid: 0,
// Unique for each copy of jQuery on the page
@@ -58,7 +58,7 @@ jQuery.extend({
// Only DOM nodes need a new unique ID for each element since their data
// ends up in the global cache
if ( isNode ) {
- elem[ internalKey ] = id = jQuery.deletedIds.pop() || ++jQuery.uuid;
+ elem[ internalKey ] = id = jQuery.deletedIds.pop() || jQuery.guid++;
Dave Methvin Owner

Clearly you haven't read http://bugs.jquery.com/ticket/12365 !

Julian Aubourg Collaborator

+1 dmethvin!

Rick Waldron Collaborator

<3

Richard Gibson Collaborator

LOL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
} else {
id = internalKey;
}
@@ -232,7 +232,7 @@ jQuery.fn.extend({
for ( l = attr.length; i < l; i++ ) {
name = attr[i].name;
- if ( name.indexOf( "data-" ) === 0 ) {
+ if ( !name.indexOf( "data-" ) ) {
Rick Waldron Collaborator

Being explicit is faster then coercion, I suspect that extend is a perf sensitive operation...

Dave Methvin Owner

I don't think it's in a path that hot; this particular code only runs once to pull in the data attrs.

Rick Waldron Collaborator

it's a nested loop...?

Julian Aubourg Collaborator

I love hot paths.

Rick Waldron Collaborator

I love hot pants

Rick Waldron Collaborator

I'd like to call a friend on this one... my eyes tricked me into thinking this was deeper then it is.

Day 1 of TC39 + trying to look at PRs. Whoops!

Dave Methvin Owner

NP, just wanted to be sure I didn't miss something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
name = jQuery.camelCase( name.substring(5) );
dataAttr( elem, name, data[ name ] );
4 src/event.js
View
@@ -364,7 +364,7 @@ jQuery.event = {
var i, j, cur, jqcur, ret, selMatch, matched, matches, handleObj, sel, related,
handlers = ( (jQuery._data( this, "events" ) || {} )[ event.type ] || []),
delegateCount = handlers.delegateCount,
- args = [].slice.call( arguments ),
+ args = core_slice.call( arguments ),
run_all = !event.exclusive && !event.namespace,
special = jQuery.event.special[ event.type ] || {},
handlerQueue = [];
@@ -973,7 +973,7 @@ jQuery.fn.extend({
},
undelegate: function( selector, types, fn ) {
// ( namespace ) or ( selector, types [, fn] )
- return arguments.length == 1? this.off( selector, "**" ) : this.off( types, selector || "**", fn );
+ return arguments.length === 1 ? this.off( selector, "**" ) : this.off( types, selector || "**", fn );
},
trigger: function( type, data ) {
Something went wrong with that request. Please try again.