Bug Tracker

Opened 9 years ago

Closed 7 years ago

#2279 closed enhancement (fixed)

faster trim

Reported by: phpmyforum Owned by: flesler
Priority: minor Milestone: 1.4.3
Component: core Version: 1.4.2
Keywords: Cc: phpmyforum
Blocked by: Blocking:


Maybe everyone had read this already... I think jQuery would really benefit from this:


Attachments (2)

jquery-4763-trim.diff (457 bytes) - added by DarkRyder 9 years ago.
Diff against rev 2763.
trim[6001].diff (2.3 KB) - added by flesler 9 years ago.
My trim function along with tests.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 9 years ago by DarkRyder

Seconded. Specifically, I'd suggest the following version, which is Steve's trim12 function with the null-value fix from bug 1395:

trim: function( text ) {
	var text = (text || "").replace(/^\s\s*/, ''),
	    ws = /\s/,
	    i = text.length;
	while ( ws.test(text.charAt(--i)) ){}
	return text.slice(0, i + 1);

Changed 9 years ago by DarkRyder

Attachment: jquery-4763-trim.diff added

Diff against rev 2763.

comment:2 Changed 9 years ago by phpmyforum

No one interested?

comment:3 Changed 9 years ago by flesler

I actually proposed one, and I think this trim12 is pretty much mine :)

comment:4 Changed 9 years ago by flesler

need: ReviewPatch
Owner: set to flesler
Status: newassigned

comment:5 Changed 9 years ago by flesler

Cc: phpmyforum added
need: PatchCommit

I think I'll add this trim function. We need to do some tests to verify it's a good choice for most situations.

Changed 9 years ago by flesler

Attachment: trim[6001].diff added

My trim function along with tests.

comment:6 Changed 8 years ago by john

After fixing #4037, .trim() is no longer used in jQuery core - FYI.

comment:21 Changed 7 years ago by john

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.