mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8199843: Optimize Integer/Long.highestOneBit()
Reviewed-by: redestad, plevart
This commit is contained in:
parent
902048c325
commit
0af73c4306
2 changed files with 2 additions and 15 deletions
|
@ -1574,13 +1574,7 @@ public final class Integer extends Number implements Comparable<Integer> {
|
||||||
* @since 1.5
|
* @since 1.5
|
||||||
*/
|
*/
|
||||||
public static int highestOneBit(int i) {
|
public static int highestOneBit(int i) {
|
||||||
// HD, Figure 3-1
|
return i & (MIN_VALUE >>> numberOfLeadingZeros(i));
|
||||||
i |= (i >> 1);
|
|
||||||
i |= (i >> 2);
|
|
||||||
i |= (i >> 4);
|
|
||||||
i |= (i >> 8);
|
|
||||||
i |= (i >> 16);
|
|
||||||
return i - (i >>> 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1719,14 +1719,7 @@ public final class Long extends Number implements Comparable<Long> {
|
||||||
* @since 1.5
|
* @since 1.5
|
||||||
*/
|
*/
|
||||||
public static long highestOneBit(long i) {
|
public static long highestOneBit(long i) {
|
||||||
// HD, Figure 3-1
|
return i & (MIN_VALUE >>> numberOfLeadingZeros(i));
|
||||||
i |= (i >> 1);
|
|
||||||
i |= (i >> 2);
|
|
||||||
i |= (i >> 4);
|
|
||||||
i |= (i >> 8);
|
|
||||||
i |= (i >> 16);
|
|
||||||
i |= (i >> 32);
|
|
||||||
return i - (i >>> 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue