Skip to content

Commit 3e9b691

Browse files
committed
Use UNSAFE.getLong() to speed up BitSetMethods#anySet()
1 parent fc8b581 commit 3e9b691

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

unsafe/src/main/java/org/apache/spark/unsafe/bitset/BitSetMethods.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
public final class BitSetMethods {
3030

3131
private static final long WORD_SIZE = 8;
32+
private static final int SIZE_OF_LONG = Long.SIZE;
3233

3334
private BitSetMethods() {
3435
// Make the default constructor private, since this only holds static methods.
@@ -71,7 +72,13 @@ public static boolean isSet(Object baseObject, long baseOffset, int index) {
7172
* Returns {@code true} if any bit is set.
7273
*/
7374
public static boolean anySet(Object baseObject, long baseOffset, long bitSetWidthInBytes) {
74-
for (int i = 0; i <= bitSetWidthInBytes; i++) {
75+
long widthInLong = bitSetWidthInBytes / SIZE_OF_LONG;
76+
for (long i = 0; i <= widthInLong; i++) {
77+
if (PlatformDependent.UNSAFE.getLong(baseObject, baseOffset + i) != 0) {
78+
return true;
79+
}
80+
}
81+
for (long i = SIZE_OF_LONG * widthInLong; i <= bitSetWidthInBytes; i++) {
7582
if (PlatformDependent.UNSAFE.getByte(baseObject, baseOffset + i) != 0) {
7683
return true;
7784
}

0 commit comments

Comments
 (0)