
AMDG Edouard A. wrote:
This is O(1). Of course a difference is that it has different entry points for the different events. This doesn't seem unreasonable to me, but if you wanted a single entry point you could do something like:
I'd like to point out that the implementation of switch is generally pretty slow, and we're talking about a code which is generally on the critical path.
Switch implies jumping to a computed address (something like jmp [eax*8+ebx]... you get the idea), this is very bad for branch prediction and for the pipeline of your beloved processor - assuming you're working on something close to the IA32 or AMD64.
There are many ways that a compiler can handle a switch statement. a) sequential if/else b) binary search c) jump table Also, a jump table does not necessarily prevent the processor from predicting the branch.
MSM's generated code will most likely contain only fixed jumps which behave much, much better, notwithstanding the fact that the template's context will help the compiler make better decisions about optimizations, resulting in favorable contexts in unconditional code.
If you care about performance, you want those jumps out of your ways.
In Christ, Steven Watanabe