I think code clarity is one thing, but performance is another - that should
be faster, so I ran a quick check.
I know it can vary across browsers, but
var timeOne = function(){var d=new Date();var b=0; for (var
i=0;i<10000000;i++) {b= parseInt(""+(127/255)*1000, 10) / 1000;}
console.log(new Date().getTime()-d.getTime());}
timeOne()
approx 715 ms in my chrome over multiple runs
var timeTwo = function(){var d=new Date();var b=0; for (var
i=0;i<10000000;i++) {b= parseInt(""+(127/255)*1000) / 1000;}
console.log(new Date().getTime()-d.getTime());}
timeTwo ()
approx 870 ms in my chrome over multiple runs
so (within the limits of this *very* basic test) I say keep it, for clarity
and speed (about 20% faster)
On Wed, Mar 15, 2017 at 3:26 PM, Justin Mclean <[email protected]>
wrote:
> Hi,
>
> > Please revert CSSUtils and investigate why parseInt is requiring the
> second argument.
>
> Even if it is a typedef bug IMO passing the base there makes the code
> intent clearer as the code is dealing with both base 16 and base 10 numbers.
>
> This is the code in question:
> public static function attributeFromColor(value:uint):String
> {
> var hexVal:String = value.toString(16);
> if(value > 16777215)
> {
> //rgba -- return rgba notation
> var rgba:Array = hexVal.match(/.{2}/g);
> for(var i:int = 0; i < 4; i++)
> {
> rgba[i] = parseInt(rgba[i], 16);
> }
> rgba[3] = parseInt(""+(rgba[3]/255)*1000, 10) / 1000;
> return "rgba(" + rgba.join(",") + ")";
> }
> return "#" + StringPadder.pad(hexVal,"0",6);
> }
>
> I added the “,10” to the second parseInt.
>
> What do others think? Should it stay or should it go?
>
> Thanks,
> Justin