[haXe] Binary Tree?

Nicolas Cannasse ncannasse at motion-twin.com
Thu Aug 30 10:22:44 CEST 2007


Stephane Le Dorze a écrit :
> And it would be safer/easier to work with using switch...
> I wonder which one is the more memory / cpu consuming (can switch
> compare in speed with if (...) ) ?

switch on enums is currently underoptimized. They consists in an Array
access + a string comparison, such as :

switch( e ) {
case Node(v,l):
case Leaf(v):
}

gets turned into :

switch( e.tag ) {
case "Node":
   var v = e.args[0], l = e.args[1];
case "Leaf":
   var v = e.args[0];
}

In future haxe version, an "index" will be added so we can switch using
integers :

switch( e.index ) {
case 0: ...
case 1: ...
}

The advantage will be that on Neko and Flash9 platforms, this kind of
switchs on integers will be optimized into a JumpTable, so no actual
comparison will be made.

Nicolas



More information about the Haxe mailing list