Skip to content

Commit a8460d2

Browse files
rwaldrontimmywil
authored andcommitted
Landing pull request 600. Remove jQuery.trim() to restore perf. Supplements #10773.
More Details: - jquery#600 - http://bugs.jquery.com/ticket/10773
1 parent 8bc60ba commit a8460d2

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

src/attributes.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -355,21 +355,24 @@ jQuery.extend({
355355
var propName, attrNames, name, l,
356356
i = 0;
357357

358-
if ( value && typeof value === "string" && elem.nodeType === 1 ) {
359-
attrNames = jQuery.trim( value ).toLowerCase().split( " " );
358+
if ( value && elem.nodeType === 1 ) {
359+
attrNames = value.toLowerCase().split( rspace );
360360
l = attrNames.length;
361361

362362
for ( ; i < l; i++ ) {
363363
name = attrNames[ i ];
364-
propName = jQuery.propFix[ name ] || name;
365364

366-
// See #9699 for explanation of this approach (setting first, then removal)
367-
jQuery.attr( elem, name, "" );
368-
elem.removeAttribute( getSetAttribute ? name : propName );
365+
if ( name ) {
366+
propName = jQuery.propFix[ name ] || name;
369367

370-
// Set corresponding property to false for boolean attributes
371-
if ( rboolean.test( name ) && propName in elem ) {
372-
elem[ propName ] = false;
368+
// See #9699 for explanation of this approach (setting first, then removal)
369+
jQuery.attr( elem, name, "" );
370+
elem.removeAttribute( getSetAttribute ? name : propName );
371+
372+
// Set corresponding property to false for boolean attributes
373+
if ( rboolean.test( name ) && propName in elem ) {
374+
elem[ propName ] = false;
375+
}
373376
}
374377
}
375378
}

test/unit/attributes.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -481,20 +481,7 @@ test("removeAttr(String)", function() {
481481
}
482482
});
483483

484-
test("removeAttr, #", function() {
485-
486-
var div = jQuery("<div />");
487-
488-
ok( div.removeAttr( "" ), "empty string" );
489-
ok( div.removeAttr(), "nothing" );
490-
ok( div.removeAttr( false ), "false" );
491-
ok( div.removeAttr( true ), "true" );
492-
ok( div.removeAttr({ }), "object" );
493-
ok( div.removeAttr( function(){} ), "function" );
494-
495-
});
496-
497-
test("removeAttr(Multi String)", function() {
484+
test("removeAttr(Multi String, variable space width)", function() {
498485
expect(8);
499486

500487
var div = jQuery("<div id='a' alt='b' title='c' rel='d'></div>"),
@@ -509,7 +496,7 @@ test("removeAttr(Multi String)", function() {
509496
equal( div.attr(key), val, "Attribute `" + key + "` exists, and has a value of `" + val + "`" );
510497
});
511498

512-
div.removeAttr( "id alt title rel " );
499+
div.removeAttr( "id alt title rel " );
513500

514501
jQuery.each( tests, function( key, val ) {
515502
equal( div.attr(key), undefined, "Attribute `" + key + "` was removed" );

0 commit comments

Comments
 (0)