Combine case labels with identical bodies. Case bodies that may fall through
to the following case label and case bodies following a possible fallthrough
are left undisturbed.
For example, consider the following input:
switch (x) {
case 0: y = 17; break;
case 1: if (z == 0) { y = 18; break; } else { y = 19 } // fallthrough else
case 2: return 22;
case 3: if (z == 0) { y = 18; break; } else { y = 19 } // fallthrough else
case 4: y = 17; break;
case 5: y = 17; break;
case 6: return 22;
}
This will be transformed into:
switch (x) {
case 0: y = 17; break;
case 1: if (z == 0) { y = 18; break; } else { y = 19 }
case 6: case 2: return 22;
case 3: if (z == 0) { y = 18; break; } else { y = 19 }
case 5: case 4: y = 17; break;
}
Cases (2, 6) and (4, 5) have been coalesced. Note that case 0 has not been
combined with cases 4 and 5 since case 4 cannot be moved due to the potential
fallthrough from case 3, and we currently only coalesce a given cases with a
preceding case and so cannot move case 0 downward.
Although this pattern is unlikely to occur frequently in hand-written code,
it can account for a significant amount of space in generated code.