-
Enhancement
-
Resolution: Fixed
-
P4
-
8
-
b103
-
generic
-
generic
-
Not verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8034602 | 7u65 | Ivan Gerasimov | P4 | Resolved | Fixed | b01 |
JDK-8022950 | 7u60 | Ivan Gerasimov | P4 | Closed | Fixed | b01 |
This is a SUNBUG for 100189: https://bugs.openjdk.java.net/show_bug.cgi?id=100189
Constructor does this:
public HashMap(int initialCapacity, float loadFactor) {
...
int capacity = 1;
while (capacity < initialCapacity)
capacity <<= 1;
...
}
It is magnitude+ faster to do this:
static final double LOG2 = Math.log(2.0);
public HashMap(int initialCapacity, float loadFactor) {
...
int capacity = 1 << ((int)Math.ceil(Math.log(initialCapacity)/LOG2 ));
...
}
Given the error checking in the head of the constructor, this code should just
plug-in.
Constructor does this:
public HashMap(int initialCapacity, float loadFactor) {
...
int capacity = 1;
while (capacity < initialCapacity)
capacity <<= 1;
...
}
It is magnitude+ faster to do this:
static final double LOG2 = Math.log(2.0);
public HashMap(int initialCapacity, float loadFactor) {
...
int capacity = 1 << ((int)Math.ceil(Math.log(initialCapacity)/LOG2 ));
...
}
Given the error checking in the head of the constructor, this code should just
plug-in.
- backported by
-
JDK-8034602 (coll) Inefficient calculation of power of two in HashMap
-
- Resolved
-
-
JDK-8022950 (coll) Inefficient calculation of power of two in HashMap
-
- Closed
-