Could you try and reorder the state checks to occur with decreasing state-transition probability? I.e. if I am currently in code, it is most likely that I will be in code next state as well, a bit less likely that I'll be in a single line comment, and even less likely that I'll be in a multiline comment. If I'm in a multiline comment, I will most likely be in a multiline comment next, or code, but unlikely to be in a single line comment.<p>Amongst a few equiprobable state transitions, ordering the checks by increasing expense might also help.