code: private void ensureCapacity(int idx) {
          int size;
          State[] grown;
  
          if (idx >= states.length) {
              size = states.length;
              while (idx >= size) {
                  size *= 2;
                  if (size < 0) {
                      // Overflow. Prevend endless loops
                      size = idx + 1;
                      break;
                  }
              }
  
              grown = new State[size];
              System.arraycopy(states, 0, grown, 0, used);
              states = grown;
          }
      }
docs: --