<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Iwo Banaś - Flex Blog &#187; Uncategorized</title>
	<atom:link href="http://www.iwobanas.com/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.iwobanas.com</link>
	<description>Adobe Flex and AIR thoughts, custom components, how-to’s...</description>
	<lastBuildDate>Tue, 02 Feb 2010 22:54:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>String Concatenation</title>
		<link>http://www.iwobanas.com/2009/06/string-concatenation/</link>
		<comments>http://www.iwobanas.com/2009/06/string-concatenation/#comments</comments>
		<pubDate>Thu, 25 Jun 2009 15:42:51 +0000</pubDate>
		<dc:creator>Iwo Banas</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ActionScript]]></category>

		<guid isPermaLink="false">http://www.iwobanas.com/?p=96</guid>
		<description><![CDATA[I am working on exporting DataGrid content to CSV (I will present result soon) and one question came to my mind:
Is ActionScript 3 String concatenation efficient?
After some googling I have found Peter Farland blog post which suggested using String.fromCharCode() method instead of string concatenation. Although my case was a little bit different because I was [...]]]></description>
			<content:encoded><![CDATA[<p>I am working on exporting DataGrid content to CSV (I will present result soon) and one question came to my mind:</p>
<h3>Is ActionScript 3 String concatenation efficient?</h3>
<p>After some googling I have found <a href="http://blogs.adobe.com/pfarland/2007/10/avoiding_string_concatenation.html">Peter Farland blog post</a> which suggested using String.fromCharCode() method instead of string concatenation. Although my case was a little bit different because I was to concatenate whole item labels (not single characters) I decided to create simple StringBuffer based on fromCharCode().</p>
<p><span id="more-96"></span></p>
<p>Here is the code of my StringBuffer class:</p>
<pre>
public class StringBuffer
{
    public var buffer:Array = new Array();

    public function add(str:String):void
    {
        for (var i:Number = 0; i < str.length; i++)
        {
            buffer.push(str.charCodeAt(i));
        }
    }

    public function toString():String
    {
        return String.fromCharCode.apply(this, buffer);
    }
}
</pre>
<p>To check the performance of my StringBuffer I have created simple test (available below).<br />
In this test I first generate array of strings (simulating labels from DataGrid) and then concatenate labels using standard “+” operator and my StringBuffer. The result surprised me a lot: <strong>standard String concatenation is about 7 times faster than my StringBuffer</strong>. After some playing with commenting out different lines of code in my StringBuffer I have found out that standard String concatenation is even faster than iterating (without any array modification) over all labels characters! It seems that Flash Player has some well optimized low level code for handling string concatenation and there is no reason to try to do it beater.</p>
<p>Conclusion:</p>
<h3>If you have set of String values and want to concatenate them don’t hesitate to use standard concatenation (string1 + string2) !</h3>
<p><br/></p>
<p>This is the test used to compare String concatenation performance (don't expect nice code - it is just a test!) <a title="Sources" href="http://www.iwobanas.com/wp-content/uploads/string_buffer_01/srcview/index.html" target="_blank">View source</a> is enabled, you can download zipped sources from <a title="StringBuffer test sources" href="http://www.iwobanas.com/wp-content/uploads/string_buffer_01/srcview/StringBuffer01.zip">here</a>.</p>
<p><iframe src="http://www.iwobanas.com/wp-content/uploads/string_buffer_01/StringBufferExample.html" width="100%" height="350" frameborder="no"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.iwobanas.com/2009/06/string-concatenation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
