Refactoring Code

claptrap clap at trap.com
Sun Mar 3 00:44:44 UTC 2024


On Saturday, 2 March 2024 at 20:27:59 UTC, Walter Bright wrote:
> https://github.com/dlang/dmd/pull/16280/files
>
> Sometimes if you stare at code long enough, its underlying 
> simplicity emerges.

Why would you use a bunch of daisy chained conditionals instead 
of a switch?

     with (Id) with (CppOperator) switch (id)
     {
         case _cast  : return Cast;
         case assign : return Assign;
         case eq     : return Eq;

etc..

IMO that is clearer, and likely faster, unless the compiler is 
smart enough to transform the daisy chain into a switch? What's 
the threshold on DMD for using a jump table? I think it's 3 or 4 
on LDC.


More information about the Digitalmars-d mailing list