About the AS3 APIs released on Labs

Adobe announced the release of several APIs on their Labs site. Theese libraries (should) speed up your developement flow. But lets go one step deeper and take a detailed look at the corelib. The corelib offers a lot of useful utils like the String and Array util.

All that stuff is very great and saves a lot of time. But there are still some inefficient parts in the corelib that scream for optimization. For example the ArrayUtil. Take the function ArrayUtil.copyArray. This function returns a copy of the given array. Now look at the implementation.

[as]
public static function copyArray(arr:Array):Array
{
var len:Number = arr.length;
var out:Array = new Array();
for(var i:Number = 0; i < len; i++)
{
out.push(arr[i]);
}
return out;
}
[/as]

Look at the beautiful for loop and then imagine an array with thousands of elements. Could take 2 or 3 seconds sometimes. I think somebody should tell Adobe about the trick using Array.slice();

[as]
var arrayCopy: Array = arrayOriginal.slice();
[/as]

This is much faster since slice() is a native function. There is also the StringUtil.replace() function which does not make use of the new regular expressions. Maybe there are more functions that could be slightly optimized. This is what I would expect from a good API. It should be well documented (which it is) and doing its job in the best way. I do not want to take a look at the other APIs since this was just a short example. But the conclusion is that you should check what you are using and how it is done.

Related Posts

1 Response to “About the AS3 APIs released on Labs”


  1. 1 betting tips poisson method

Leave a Reply






Close
E-mail It