Replace use of method findLoopEnd with a map between loop start and end indices built by scanning the tokens once.