While i was making the code for the modification to support stage3D i realized that the functions quicksort
and quicksortBy
in the FP
are not as fast as they can be. They use binary serch to sort the array/vector. Binary serch is the fastest way to serch into an array/vector but to sort it there is faster method. I post the code and if someone wants to make pull request it would be great (my github have enough with a pendent pull request and making the stage3D support).
/** @private Quicksorts the array. */
private static function quicksort(a:Object, left:int, right:int, ascending:Boolean):void
{
var i:int, j:int, temp:*;
i = left + 1;
while (i <= right)
{
temp = a[i];
j = i - 1;
while (j >= left && ((ascending && temp > a[j]) || (!ascending && temp < a[j])))
{
a[j + 1] = a[j];
j--;
}
a[j + 1] = temp;
i++;
}
}
/** @private Quicksorts the array by the property. */
private static function quicksortBy(a:Object, left:int, right:int, ascending:Boolean, property:String):void
{
var i:int, j:int, temp:*;
i = left + 1;
while (i <= right)
{
temp = a[i];
j = i - 1;
while (j >= left && ((ascending && temp > a[j][property]) || (!ascending && temp < a[j][property])))
{
a[j + 1] = a[j];
j--;
}
a[j + 1] = temp;
i++;
}
}
PD: as you can see is way shorter and uses 1 loop less.