<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Faster JavaScript Trim</title>
	<atom:link href="http://blog.stevenlevithan.com/archives/faster-trim-javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.stevenlevithan.com/archives/faster-trim-javascript</link>
	<description>A JavaScript and regular expression centric blog</description>
	<lastBuildDate>Thu, 09 Feb 2012 10:18:35 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Copperwheat</title>
		<link>http://blog.stevenlevithan.com/archives/faster-trim-javascript/comment-page-4#comment-184305</link>
		<dc:creator>Copperwheat</dc:creator>
		<pubDate>Thu, 02 Feb 2012 02:09:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/javascript/faster-trim/#comment-184305</guid>
		<description>Although tests are performed with old browsers, your article really helps. I never thought different regular expressions make such big differences. Thank you for your work. (I wish there is an update with current browsers.)</description>
		<content:encoded><![CDATA[<p>Although tests are performed with old browsers, your article really helps. I never thought different regular expressions make such big differences. Thank you for your work. (I wish there is an update with current browsers.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy Harrison</title>
		<link>http://blog.stevenlevithan.com/archives/faster-trim-javascript/comment-page-4#comment-155722</link>
		<dc:creator>Andy Harrison</dc:creator>
		<pubDate>Thu, 17 Nov 2011 21:15:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/javascript/faster-trim/#comment-155722</guid>
		<description>Thanks for the inspiring article!

After much testing in the latest browsers (FF 7, IE 9, Safari 5, Chrome 15, and Opera 11.5) and with many strings, this is the implementation I&#039;ve come up with. It is often faster than trim12, and is MUCH faster when there are more than a few spaces at the end of the string.

var trimN;
if(window.navigator.mozIsLocallyAvailable)	//Firefox
	//Firefox is faster this way. So is Safari but I can&#039;t reliably detect it.
	trimN = function (str) {
		str = str.match(/\S+(?:\s+\S+)*/);
		return str ? str[0] : &quot;&quot;;
	}
else	//other browsers
	trimN = function (str) {
		str = str.replace(/^\s+/, &quot;&quot;);
		if(!str) return &quot;&quot;;
		str = str.match(/^[\s\S]*\S(?=\s*$)/);
		return str ? str[0] : &quot;&quot;;
	}</description>
		<content:encoded><![CDATA[<p>Thanks for the inspiring article!</p>
<p>After much testing in the latest browsers (FF 7, IE 9, Safari 5, Chrome 15, and Opera 11.5) and with many strings, this is the implementation I&#8217;ve come up with. It is often faster than trim12, and is MUCH faster when there are more than a few spaces at the end of the string.</p>
<p>var trimN;<br />
if(window.navigator.mozIsLocallyAvailable)	//Firefox<br />
	//Firefox is faster this way. So is Safari but I can&#8217;t reliably detect it.<br />
	trimN = function (str) {<br />
		str = str.match(/\S+(?:\s+\S+)*/);<br />
		return str ? str[0] : &#8220;&#8221;;<br />
	}<br />
else	//other browsers<br />
	trimN = function (str) {<br />
		str = str.replace(/^\s+/, &#8220;&#8221;);<br />
		if(!str) return &#8220;&#8221;;<br />
		str = str.match(/^[\s\S]*\S(?=\s*$)/);<br />
		return str ? str[0] : &#8220;&#8221;;<br />
	}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ????</title>
		<link>http://blog.stevenlevithan.com/archives/faster-trim-javascript/comment-page-3#comment-155492</link>
		<dc:creator>????</dc:creator>
		<pubDate>Thu, 17 Nov 2011 04:58:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/javascript/faster-trim/#comment-155492</guid>
		<description>[...] ???????dojo base???dojo??JS????????????dojo?????????trim? ???????dojo.string???dojo?string????????????????????? ???Dojo?????????trim??????????????????????Faster Javascript Trim [...]</description>
		<content:encoded><![CDATA[<p>[...] ???????dojo base???dojo??JS????????????dojo?????????trim? ???????dojo.string???dojo?string????????????????????? ???Dojo?????????trim??????????????????????Faster Javascript Trim [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Digitowl</title>
		<link>http://blog.stevenlevithan.com/archives/faster-trim-javascript/comment-page-3#comment-143956</link>
		<dc:creator>Digitowl</dc:creator>
		<pubDate>Wed, 12 Oct 2011 19:45:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/javascript/faster-trim/#comment-143956</guid>
		<description>Results @ 5000 times (note trim1 uses the code from my previous post):

This is only in Firefox, however.

Original length: 27661
trim1: 2ms (length: 27657)
trim2: 1706ms (length: 27654)
trim3: 1809ms (length: 27654)
trim4: 1322ms (length: 27654)
trim5: 724ms (length: 27654)
trim6: 9155ms (length: 27654)
trim7: 7107ms (length: 27654)
trim8: 4084ms (length: 27654)
trim9: 2436ms (length: 27654)
trim10: 12ms (length: 27654)
trim11: 491ms (length: 27654)
trim12: 431ms (length: 27654)

Thanks for the great post.</description>
		<content:encoded><![CDATA[<p>Results @ 5000 times (note trim1 uses the code from my previous post):</p>
<p>This is only in Firefox, however.</p>
<p>Original length: 27661<br />
trim1: 2ms (length: 27657)<br />
trim2: 1706ms (length: 27654)<br />
trim3: 1809ms (length: 27654)<br />
trim4: 1322ms (length: 27654)<br />
trim5: 724ms (length: 27654)<br />
trim6: 9155ms (length: 27654)<br />
trim7: 7107ms (length: 27654)<br />
trim8: 4084ms (length: 27654)<br />
trim9: 2436ms (length: 27654)<br />
trim10: 12ms (length: 27654)<br />
trim11: 491ms (length: 27654)<br />
trim12: 431ms (length: 27654)</p>
<p>Thanks for the great post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Digitowl</title>
		<link>http://blog.stevenlevithan.com/archives/faster-trim-javascript/comment-page-3#comment-143950</link>
		<dc:creator>Digitowl</dc:creator>
		<pubDate>Wed, 12 Oct 2011 19:34:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/javascript/faster-trim/#comment-143950</guid>
		<description>This function is similar to trim12, except it does not use regx for leading spaces. Tested in Firefox 7.0.1 with Firebug 1.8.3 on desktop with 4G RAM 64 bit Win7 OS on 2.50 GHz Dual-core CPU, etc...

What I did to test it:

Went to your benchmark page &gt; opened Firebug &gt; right-clicked on the containing script tag &gt; selected &quot;Edit HTML&quot; &gt; replaced trim1&#039;s code with the following function&#039;s code block.

.....function trimN() {
..........var f = 0, t = str.length - 1;
..........while (str.charAt(f) === &#039; &#039;) { ++f; }
..........while (str.charAt(t) === &#039; &#039;) { --t; }
..........return str.slice(f, t);
.....}

Result: 0ms</description>
		<content:encoded><![CDATA[<p>This function is similar to trim12, except it does not use regx for leading spaces. Tested in Firefox 7.0.1 with Firebug 1.8.3 on desktop with 4G RAM 64 bit Win7 OS on 2.50 GHz Dual-core CPU, etc&#8230;</p>
<p>What I did to test it:</p>
<p>Went to your benchmark page &gt; opened Firebug &gt; right-clicked on the containing script tag &gt; selected &#8220;Edit HTML&#8221; &gt; replaced trim1&#8242;s code with the following function&#8217;s code block.</p>
<p>&#8230;..function trimN() {<br />
&#8230;&#8230;&#8230;.var f = 0, t = str.length &#8211; 1;<br />
&#8230;&#8230;&#8230;.while (str.charAt(f) === &#8216; &#8216;) { ++f; }<br />
&#8230;&#8230;&#8230;.while (str.charAt(t) === &#8216; &#8216;) { &#8211;t; }<br />
&#8230;&#8230;&#8230;.return str.slice(f, t);<br />
&#8230;..}</p>
<p>Result: 0ms</p>
]]></content:encoded>
	</item>
</channel>
</rss>

