4 ms·
A compiler like gcc will (or at least used to) translate small switch statements into compare/jmp assembler, and larger switch statements into a jump table usin
by julian_1 10y ago
A compiler like gcc will (or at least used to) translate small switch statements into compare/jmp assembler, and larger switch statements into a jump table using indexes/modulos on the test expression.
The tipping point for when the compiler decides to switch strategies, is obviously architecture dependent but could also be influenced by what flags are set and whether to favor for small code side, or highest speed.
I suspect, the code could have been written using two switch statements - and probably achieved the same effect in terms of the generated assembler, as well as be more idiomatic.