code: private void ensureCapacity(int idx) {
          int size;
          int[] grownEnds;
          Range[] grownInputs;
  
          if (idx >= inputs.length) {
              size = inputs.length; // same as ends.length
              while (idx >= size) {
                  size *= 2;
                  if (size < 0) {
                      // overflow. prevent endless loops
                      size = idx + 1;
                      break;
                  }
              }
  
              grownEnds = new int[size];
              System.arraycopy(ends, 0, grownEnds, 0, used);
              ends = grownEnds;
  
              grownInputs = new Range[size];
              System.arraycopy(inputs, 0, grownInputs, 0, used);
              inputs = grownInputs;
          }
      }
docs: --