[Prototype-core] Re: Improving String.strip performance

2008-05-14 Thread John-David Dalton

Also some other performance tips:
http://www.sitepen.com/blog/2008/05/09/string-performance-an-analysis/

disccomp, feel free to submit a ticket and a patch for the current
String#strip
http://www.prototypejs.org/contribute

- JDD
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: Improving String.strip performance

2008-05-14 Thread Ken Snyder

disccomp wrote:
 Please see this excellent breakdown of this function on cross-browser
 performance to better understand the available solutions.
 http://blog.stevenlevithan.com/archives/faster-trim-javascript
   
Awesome analysis!

I wonder if trim12 might be improved by avoiding calling slice if there 
is no trailing white space:

function trim12 (str) {
var str = str.replace(/^\s\s*/, ''),
ws = /\s/,
i = str.length,
len = i;
while (ws.test(str.charAt(--i)));
return i + 1  len ? str.slice(0, i + 1) : str;
}


Also, you did not say it explicitly, but are you saying that /\s/.test() 
is faster than whitespace.indexOf() ?

- Ken

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---