A switch statement is not a branching instruction. It is a small optimization problem that you hand to the compiler: here is a set of integer values, here is what each value should do, now figure out the cheapest machine code that respects the semantics. GCC treats that problem seriously enough to maintain three distinct lowering strategies, a dynamic programming pass to partition your case labels, and a profitability heuristic that is counted in comparisons rather than in case labels. If you write interpreters, parsers, protocol handlers, or any hot dispatch loop, the difference between those three outcomes is the difference between one indirect jump and a walk down a binary tree.
This article walks through what GCC actually emits for each shape of switch, why the heuristic fires when it does, and how to check which machine your own switch became.…