hpack/src/main/java/com/twitter/hpack/DynamicTable.java
public void setCapacity(int capacity) {
    if (capacity < 0) {
      throw new IllegalArgumentException("Illegal Capacity: "+ capacity);
    }

    // initially capacity will be -1 so init won't return here
    if (this.capacity == capacity) {
      return;
    }
    this.capacity = capacity;

    if (capacity == 0) {
      clear();
    } else {
      // initially size will be 0 so remove won't be called
      while (size > capacity) {
        remove();
      }
    }

    int maxEntries = capacity / HEADER_ENTRY_OVERHEAD;
    if (capacity % HEADER_ENTRY_OVERHEAD != 0) {
      maxEntries++;
    }

    // check if capacity change requires us to reallocate the array
    if (headerFields != null && headerFields.length == maxEntries) {
      return;
    }

    HeaderField[] tmp = new HeaderField[maxEntries];

    // initially length will be 0 so there will be no copy
    int len = length();
    int cursor = tail;
    for (int i = 0; i < len; i++) {
      HeaderField entry = headerFields[cursor++];
      tmp[i] = entry;
      if (cursor == headerFields.length) {
        cursor = 0;
      }
    }

    this.tail = 0;
    this.head = tail + len;
    this.headerFields = tmp;
  }
public void setCapacity(int capacity) {
    if (capacity < 0) {
      throw new IllegalArgumentException("Illegal Capacity: "+ capacity);
    }

    // initially capacity will be -1 so init won't return here
    if (this.capacity == capacity) {
      return;
    }
    this.capacity = capacity;

    if (capacity == 0) {
      clear();
    } else {
      // initially size will be 0 so remove won't be called
      while (size > capacity) {
        remove();
      }
    }

    int maxEntries = capacity / HEADER_ENTRY_OVERHEAD;
    if (capacity % HEADER_ENTRY_OVERHEAD != 0) {
      maxEntries++;
    }

    // check if capacity change requires us to reallocate the array
    if (headerFields != null && headerFields.length == maxEntries) {
      return;
    }

    HeaderField[] tmp = new HeaderField[maxEntries];

    // initially length will be 0 so there will be no copy
    int len = length();
    int cursor = tail;
    for (int i = 0; i < len; i++) {
      HeaderField entry = headerFields[cursor++];
      tmp[i] = entry;
      if (cursor == headerFields.length) {
        cursor = 0;
      }
    }

    this.tail = 0;
    this.head = tail + len;
    this.headerFields = tmp;
  }
public void setCapacity ( int capacity ) { if ( capacity < 0 ) { throw new IllegalArgumentException ( "Illegal Capacity: " + capacity ) ; } // initially capacity will be -1 so init won't return here if ( this . capacity == capacity ) { return ; } this . capacity = capacity ; if ( capacity == 0 ) { clear ( ) ; } else { // initially size will be 0 so remove won't be called while ( size > capacity ) { remove ( ) ; } } int maxEntries = capacity / HEADER_ENTRY_OVERHEAD ; if ( capacity % HEADER_ENTRY_OVERHEAD != 0 ) { maxEntries ++ ; } // check if capacity change requires us to reallocate the array if ( headerFields != null && headerFields . length == maxEntries ) { return ; } HeaderField [ ] tmp = new HeaderField [ maxEntries ] ; // initially length will be 0 so there will be no copy int len = length ( ) ; int cursor = tail ; for ( int i = 0 ; i < len ; i ++ ) { HeaderField entry = headerFields [ cursor ++ ] ; tmp [ i ] = entry ; if ( cursor == headerFields . length ) { cursor = 0 ; } } this . tail = 0 ; this . head = tail + len ; this . headerFields = tmp ; }
Set the maximum size of the dynamic table.
Entries are evicted from the dynamic table until the size of the table
is less than or equal to the maximum size.
Set the maximum size of the dynamic table . Entries are evicted from the dynamic table until the size of the table is less than or equal to the maximum size .