src/java.net.http/share/classes/jdk/internal/net/http/hpack/SimpleHeaderTable.java
--- a/src/java.net.http/share/classes/jdk/internal/net/http/hpack/SimpleHeaderTable.java Wed May 02 10:47:16 2018 +0200
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/hpack/SimpleHeaderTable.java Wed May 02 02:36:17 2018 -0700
@@ -28,6 +28,7 @@
import java.util.NoSuchElementException;
+import static jdk.internal.net.http.common.Utils.pow2Size;
import static jdk.internal.net.http.hpack.HPACK.Logger.Level.EXTRA;
import static jdk.internal.net.http.hpack.HPACK.Logger.Level.NORMAL;
import static java.lang.String.format;
@@ -306,8 +307,8 @@
Object[] elements;
CircularBuffer(int capacity) {
- this.capacity = capacity;
- elements = new Object[capacity];
+ this.capacity = pow2Size(capacity);
+ elements = new Object[this.capacity];
}
void add(E elem) {
@@ -316,7 +317,7 @@
format("No room for '%s': capacity=%s", elem, capacity));
}
elements[head] = elem;
- head = (head + 1) % capacity;
+ head = (head + 1) & (capacity - 1);
size++;
}
@@ -327,7 +328,7 @@
}
E elem = (E) elements[tail];
elements[tail] = null;
- tail = (tail + 1) % capacity;
+ tail = (tail + 1) & (capacity - 1);
size--;
return elem;
}
@@ -339,7 +340,7 @@
format("0 <= index <= capacity: index=%s, capacity=%s",
index, capacity));
}
- int idx = (tail + (size - index - 1)) % capacity;
+ int idx = (tail + (size - index - 1)) & (capacity - 1);
return (E) elements[idx];
}
@@ -350,7 +351,8 @@
newCapacity, size));
}
- Object[] newElements = new Object[newCapacity];
+ int capacity = pow2Size(newCapacity);
+ Object[] newElements = new Object[capacity];
if (tail < head || size == 0) {
System.arraycopy(elements, tail, newElements, 0, size);
@@ -362,7 +364,7 @@
elements = newElements;
tail = 0;
head = size;
- this.capacity = newCapacity;
+ this.capacity = capacity;
}
}
}