This trim is faster than the regex-based one on most cases. Even for a small string, I get 30ms vs 55ms on FF3.
IE is the only one that seems to have a great regex engine, or a dreadful js engine. In some cases, on very small strings, it is indeed slower. On Tue, Nov 4, 2008 at 7:14 PM, ricardobeat <[EMAIL PROTECTED]> wrote: > > Very clever implementation of yours. > > I believe the question is *what for* is the function being currently > used? I believe most common cases are very short (<15 chars) strings, > usually small bits of data that are going to be thrown as hash keys or > something. In that case the standard regexp version is still faster. > > Maybe trim() should switch between these two modes depending on the > strings length? > > On Nov 4, 2:40 pm, Ariel Flesler <[EMAIL PROTECTED]> wrote: >> Hi >> >> As a follow up to Steven Levithan's post about string trimming[1]. >> I made a second version of trim that is performing quite well among >> different browsers (the 1st one I posted on his blog). >> >> If you're interested, I wrote an article[2] about this. If the >> implementation proves to be well rounded and effective, it could make >> it into the core, eventually. >> >> There's already a ticket[3] requesting a faster jQuery.trim() >> function. >> >> Comments (and testing) are much appreciated. >> >> Cheers >> >> [1]http://blog.stevenlevithan.com/archives/faster-trim-javascript >> [2]http://flesler.blogspot.com/2008/11/fast-trim-function-for- >> javascript.html >> [3]http://dev.jquery.com/ticket/2279 >> -- >> Ariel Fleslerhttp://flesler.blogspot.com > > > -- Ariel Flesler http://flesler.blogspot.com