lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On 2018-01-28 05:37 PM, Paige DePol wrote:
Soni They/Them L. <fakedme@gmail.com> wrote:

Otherwise, for the example you gave... just use if/else in the first place,
or only use non-constant or non-conflicting values as case values?

~Paige
Why not make it explicit? If you want the constant cases to come first,
put the constant cases first?
Due to the nature of how the switch/case works the case values would have
to be broken down into two distinct categories; constant and non-constant.
I would say that the constant value case blocks have priority as they are
known at compile time and are explicitly declared, the non-constant ones
therefore would be checked after the constant ones... were I to implement
the ability to have non-constant case blocks at all.

With the example you gave you could just use an if/else statement. The idea
of switch/case, and the way I implemented it, is not just to be syntactic
sugar for if/else blocks but to offer more performance when selecting code
paths from many known-at-compile-time options.

I like the idea of being able to specify non-constant case values, however,
there will have to be some limitations due to the nature of the problem.
Also, arguably, once you start executing functions to obtain case values
the entire point of switch/case, the speed improvement, goes away as well.

I've checked the asm output of rustc over and over. It doesn't have jump tables. I couldn't get it to produce jump tables no matter what I tried.

Jump tables are unnecessary. The syntax sugar is nice when comparing the same variable to many many values, as it avoids typos (e.g. `hello == 1` in the first "if", `helo == 2` in the second "if").

~Paige



--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.