It sounds like a micro-optimization, but it saves some bytes and doesn’t look 
like a functional change, so go knock yourself out… ;-)

> On Jun 6, 2017, at 1:43 PM, Justin Mclean <jus...@classsoftware.com> wrote:
> 
> Hi,
> 
> Just profiled these with a variety of inputs and the first is around 3 times 
> as fast as the second.
> 
> I added a null check to stop the RTE, if the null check is not needed it can 
> be removed from both.
> 
> public function test(str:String):Number {
>    var pixels:Number = NaN;
>    if (str !== null && str.indexOf('%') === -1)
>        pixels = parseFloat(str);
> 
>    return pixels;  
> }
> 
> public function test2(str:String):Number {
>    var pixels:Number;
>    if (str !== null && str.indexOf('%') != -1)
>        pixels = NaN;
>    else if (str !== null && str.length == 0)
>        pixels = NaN;
>    else
>        pixels = parseFloat(str);
> 
>    return pixels;
> }
> 
> Thanks,
> Justin
> 

Reply via email to