def _optimize_switches(self, minimumLength=2):
      '''
      converts sequences of compare/cjmp to switch instructions
      this must happen BEFORE linking
      minimumLength describes the minum amount of sequential compare/cjmp combinations
      needed to switch to a switch

      AUTOMATICALLY called by compile
      '''
      # locate all the targets of switch statements
      q = util.OneTimeQueue()
      targets = {}
      for i in range(len(self)):
        if isinstance(self[i], Compare) and isinstance(self[i+1], CondJmp):
          q.append(i)

      while q:
        front = q.popleft()
        i = front
        targets[i] = {}
        targets[i][self[i].arg1] = self[i+1].arg1
        while isinstance(self[i+2], Compare) and isinstance(self[i+3], CondJmp):
          i += 2
          targets[front][self[i].arg1] = self[i+1].arg1
          q.remove(i)
        if len(targets[front]) < minimumLength:
          # don't convert single cjmps to switches
          del targets[front]

      # now replace sequences with their switch statements
      # in order for our instruction numbers to be valid, do this
      # in reverse order
      _keys = targets.keys()
      _keys.sort()
      _keys.reverse()
      for i in _keys:
        del self[i:i+(len(targets[i])*2)]
        self.insert(i, Switch(targets[i]))