Bug Tracker

Modify

Ticket #2279 (closed enhancement: fixed)

Opened 6 years ago

Last modified 4 years ago

faster trim

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

Description

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

 http://blog.stevenlevithan.com/archives/faster-trim-javascript

Attachments

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

Change History

comment:1 Changed 6 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 6 years ago by DarkRyder

Diff against rev 2763.

comment:2 Changed 6 years ago by phpmyforum

No one interested?

comment:3 Changed 6 years ago by flesler

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

comment:4 Changed 6 years ago by flesler

  • need changed from Review to Patch
  • Owner set to flesler
  • Status changed from new to assigned
  • Milestone changed from 1.2.3 to 1.3

comment:5 Changed 5 years ago by flesler

  • Cc phpmyforum added
  • need changed from Patch to Commit

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 5 years ago by flesler

My trim function along with tests.

comment:6 Changed 5 years ago by john

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

comment:21 Changed 4 years ago by john

  • Status changed from assigned to closed
  • Version changed from 1.2.2 to 1.4.2
  • Resolution set to fixed
  • Milestone changed from 1.3 to 1.4.3

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.