That this reordering is a net win for us in this particular case is nothing but mere luck, AFAICT. In fact, if you take the time to experiment a bit with type-switches, especially ones with more than two cases, you'll find that the compiler always shuffles the cases using some kind of deterministic heuristics.
What those heuristics are, I don't know (but as always, I'd love to if you do).
Type-switches have sorted and runtime use a Binary search to find the result , so the time complexity is log2(n).
if necessary, i am glad to pull request to this repo about how the golang compile do
Type-switches have sorted and runtime use a Binary search to find the result , so the time complexity is log2(n). if necessary, i am glad to pull request to this repo about how the golang compile do