code: protected void ensureBufferSpace(int expectedAdditions) {
      final int bufferLen = buffer.length;
      final int elementsCount = size();
  
      if (elementsCount + expectedAdditions >= bufferLen) {
        final int emptySlot = 1; // deque invariant: always an empty slot.
        final int newSize = resizer.grow(bufferLen, elementsCount + emptySlot, expectedAdditions);
        assert newSize >= (elementsCount + expectedAdditions + emptySlot) : "Resizer failed to"
            + " return sensible new size: " + newSize + " <= " + (elementsCount + expectedAdditions);
  
        try {
          final KType[] newBuffer = Intrinsics.<KType> newArray(newSize);
          if (bufferLen > 0) {
            toArray(newBuffer);
            tail = elementsCount;
            head = 0;
          }
          this.buffer = newBuffer;
        } catch (OutOfMemoryError e) {
          throw new BufferAllocationException(
              "Not enough memory to allocate new buffers: %,d -> %,d", 
              e, bufferLen, newSize);
        }
      }
    }
docs: Ensures the internal buffer has enough free slots to store
  <code>expectedAdditions</code>. Increases internal buffer size if needed.