How to clean an array in Haxe correctly?

What is the most efficient way to clear an array in Haxe? Currently, I'm just assigning a variable to an empty array.

I found this on the internet:

public static function clear(arr:Array<Dynamic>) {
    #if cpp
    arr.splice(0, arr.length);
    #else
    untyped arr.length = 0;
    #end
}

Is this the best way? I am concerned about two goals, JS and CPP.

+6
source share
1 answer

For the most part, you can simply use reassignment for an empty array to clear the array; this becomes problematic if array reference is important. In this case, it works well for you.

, , . , Haxe , - , , , Neko HTML5 . , .

8 1048576 . :

Splice Clear:

array.splice(0, array.length);

Clear:

untyped array.length = 0;

:

array = [];

Pop Clear:

while (array.length > 0)
    array.pop();

, , , .

Neko:

  • Splice: 0,51
  • : 0.069
  • : 0,34
  • : 0,071 0,179 ( )

HTML5:

  • Splice: 0.29
  • : 0.046
  • : 0.032
  • : 0,012

64- Windows 7 Firefox.

, while loop javascript; , - . , .

Github, - , , , Neko HTML5.

+7

Source: https://habr.com/ru/post/1682307/


All Articles