3 ms·
The only difference of these two variants is that cgoto skips the switch range check at the beginning. Switch is largely implemented as such a jump table also.
by rurban 6y ago
The only difference of these two variants is that cgoto skips the switch range check at the beginning.
Switch is largely implemented as such a jump table also. Compilers didn't get that smart yet to optimize switch tables to something better, even if it's constant. A vm or jit on the other hand could exploit bitmasks of ops or neighbor frequencies of ops better. LuaJit did that by hand.