Skip to content
Permalink
Browse files

Do jQuery.trim in less bytes (-5).

  • Loading branch information...
timmywil committed Jun 21, 2012
1 parent e2497c6 commit 26bdbb806eeb1d8e1881b3fc11ff298eb4d1dca0
Showing with 4 additions and 9 deletions.
  1. +4 −9 src/core.js
@@ -36,8 +36,9 @@ var
// Used for detecting and trimming whitespace
core_rnotwhite = /\S/,
core_rspace = /\s+/,
trimLeft = /^\s+/,
trimRight = /\s+$/,

// IE doesn't match non-breaking spaces with \s
rtrim = core_rnotwhite.test("\xA0") ? (/^[\s\xA0]+|[\s\xA0]+$/g) : /^\s+|\s+$/g,

// A simple way to check for HTML strings
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
@@ -601,7 +602,7 @@ jQuery.extend({
function( text ) {
return text == null ?
"" :
text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
text.toString().replace( rtrim, "" );
},

// results is for internal usage only
@@ -913,11 +914,5 @@ if ( jQuery.browser.webkit ) {
jQuery.browser.safari = true;
}

// IE doesn't match non-breaking spaces with \s
if ( core_rnotwhite.test( "\xA0" ) ) {
trimLeft = /^[\s\xA0]+/;
trimRight = /[\s\xA0]+$/;
}

// All jQuery objects should point back to these
rootjQuery = jQuery(document);

2 comments on commit 26bdbb8

@kswedberg

This comment has been minimized.

Copy link
Member

kswedberg replied Jun 22, 2012

Hey Timmy,

Just a heads up: The two-replace trim that you got rid of was at least partly the result of a monumental "bikeshedding" thread: http://forum.jquery.com/topic/faster-jquery-trim

So you might get people wondering why you decided to make jQuery.trim() "slower."

@rwaldron

This comment has been minimized.

Copy link
Member

rwaldron replied Jun 22, 2012

My favorite part is this... http://forum.jquery.com/topic/faster-jquery-trim#14737000000647377

String.trim??

Please sign in to comment.
You can’t perform that action at this time.