c++ - Avoiding Branch Operations in Switch Statements -


this question has answer here:

instead of switch statement running iterating through branch after branch, there away make assembly list in array goto statement? or optimized in compiler?

such optimization immensely large switch statements constant values.

ex:

switch(test) { case 1: // break; case 2: // break; } 

"optimized":

action_link[] = {action_1, action_2}; goto action_link[test];  action_1: // action_2: // 

the compiler make decision you, based on optimisation settings , heuristics might make jump table.

in many simple situations, compiler might decide naive test-and-jump chain faster or smaller equivalent jump table.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -