mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8203279: Faster rounding up to nearest power of two
Reviewed-by: martin, redestad
This commit is contained in:
parent
088dbd5ce8
commit
ee601ac627
3 changed files with 3 additions and 18 deletions
|
@ -376,12 +376,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
|
|||
* Returns a power of two size for the given target capacity.
|
||||
*/
|
||||
static final int tableSizeFor(int cap) {
|
||||
int n = cap - 1;
|
||||
n |= n >>> 1;
|
||||
n |= n >>> 2;
|
||||
n |= n >>> 4;
|
||||
n |= n >>> 8;
|
||||
n |= n >>> 16;
|
||||
int n = -1 >>> Integer.numberOfLeadingZeros(cap - 1);
|
||||
return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue