Optimizing compilers (including GCC) will compile the switch statement into a jump table (making the switch statement just as fast as the thing you are trying to build) IF the following conditions are true:
Your wiring closets (state numbers) start from scratch.
Your wiring closets are strictly increasing.
You don't skip integers in your switch cases.
There are enough cases when the transition table is actually faster (several dozen comparisons and errors in the method of checking each case with switch statements are actually faster than the transition table).
This has the advantage of allowing you to write your own code in standard C rather than relying on a compiler extension. He will work just as fast at GCC. It will also work just as fast on most optimizing compilers (I know the Intel compiler does this, not sure about Microsoft). And it will work, albeit more slowly, on any compiler.
Damnatio Memoriae Apr 16 '16 at 18:25 2016-04-16 18:25
source share