Thanks Jb. BTW, do you know if switch statements in IL are done in linear or constant time? For example, if I have an a set of instruction labels as jump targets in an array using the OpCodes.Switch instruction and I already have the target index computed at runtime, will it still have to do a comparison for each case? And is there a limit on how many labels one can have in a switch statement done in IL?
On Apr 18, 12:57 am, Jb Evain <[email protected]> wrote: > Hey Philip, > > On 4/6/09, Philip_L <[email protected]> wrote: > > > switch(someString) > > { > > case "a": > > break; > > case "b": > > break; > > default: > > break; > > That's compiled using a Dictionary<>. A switch is quite complex > actually. If you have: > int a; > switch (a) { > case 0: > case 1: > case 12: > case 74: > > } > > It's likely that only the case 0 and 1 will be compiled using a switch > opcode, the rest will be compiled as a short serie of comparison. I > suggest you write a few examples and see in ildasm what csc emits, > it's quite interesting (I had to do that for Cecil.Decompiler, it's > actually not that fun to reconstruct a switch statement from what is > actually compiled). > > -- > Jb Evain <[email protected]> --~--~---------~--~----~------------~-------~--~----~ -- mono-cecil -~----------~----~----~----~------~----~------~--~---
