#167 if-blocks for ranges instead of large switch-blocks


Quez generates very large switch blocks where many ranges could be replaced with if-blocks.

Ex. Quex currently outputs large switch blocks like the following:

    switch( input ) {
        case 0x0: QUEX_GOTO_RELOAD_FORWARD(6079, 6101);

        case 0x2: 
        case 0x3: 
        case 0x4: 
        case 0x5: 
        case 0x6: 
        case 0x7: 
        case 0x8: 
        case 0x9: 
        case 0xA: 
        case 0xB: 
        case 0xC: 
        case 0xD: 
        case 0xE: 
        case 0xF: 
        case 0x10: 
        case 0x11: 
        case 0x12: 
        case 0x13: 
        case 0x14: 
        case 0x15: 
        case 0x16: 
        case 0x17: 
        case 0x18: 
        case 0x19: 
        case 0x1A: 
        case 0x1B: 
        case 0x1C: 
        case 0x1D: 
        case 0x1E: 
        case 0x1F: 
        case 0x20: 
        case 0x21: 
        case 0x22: 
        case 0x23: 
        case 0x24: 
        case 0x25: 
        case 0x26: 
        case 0x27: 
        case 0x28: 
        case 0x29: 
        case 0x2A: 
        case 0x2B: 
        case 0x2C: goto _6085;


, which could also be coded like:

if (input >=0x2 && input <= 0x2C ) goto _6058;

This kind of range checks should be a lot faster to execute than the large switch block currently generated by Quex.

Kind regards,


  • 'switch' gives a hint to the compiler to implement branch tables. Those tables
    are much faster than bisectioning if-statements--in general. I can think of an
    option '--no-switch' if you want. But do not expect a performance increase.