-
Notifications
You must be signed in to change notification settings - Fork 29k
SPARK-7450 Use UNSAFE.getLong() to speed up BitSetMethods#anySet() #5897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3e9b691
4ca0ef6
63ee050
093b7a4
855374b
75a467b
817e3f9
83f9f87
b51dcaf
1719c5b
473bf9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,7 @@ | |
| */ | ||
| public final class BitSetMethods { | ||
|
|
||
| private static final long WORD_SIZE = 8; | ||
| static final long WORD_SIZE = 8; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could remain private. |
||
|
|
||
| private BitSetMethods() { | ||
| // Make the default constructor private, since this only holds static methods. | ||
|
|
@@ -70,9 +70,10 @@ public static boolean isSet(Object baseObject, long baseOffset, int index) { | |
| /** | ||
| * Returns {@code true} if any bit is set. | ||
| */ | ||
| public static boolean anySet(Object baseObject, long baseOffset, long bitSetWidthInBytes) { | ||
| for (int i = 0; i <= bitSetWidthInBytes; i++) { | ||
| if (PlatformDependent.UNSAFE.getByte(baseObject, baseOffset + i) != 0) { | ||
| public static boolean anySet(Object baseObject, long baseOffset, long bitSetWidthInWords) { | ||
| long addr = baseOffset; | ||
| for (int i = 0; i < bitSetWidthInWords; i++, addr += WORD_SIZE) { | ||
| if (PlatformDependent.UNSAFE.getLong(baseObject, addr) != 0) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,8 @@ public void basicOps() { | |
| for (int i = 0; i < bs.capacity(); i++) { | ||
| Assert.assertFalse(bs.isSet(i)); | ||
| } | ||
| // another form of asserting that the bit set is empty | ||
| Assert.assertFalse(bs.anySet()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still think that we should write a proper unit test for |
||
|
|
||
| // Set every bit and check it. | ||
| for (int i = 0; i < bs.capacity(); i++) { | ||
|
|
@@ -52,6 +54,11 @@ public void basicOps() { | |
| bs.unset(i); | ||
| Assert.assertFalse(bs.isSet(i)); | ||
| } | ||
|
|
||
| // Make sure anySet() can detect any set bit | ||
| bs = createBitSet(256); | ||
| bs.set(64); | ||
| Assert.assertTrue(bs.anySet()); | ||
| } | ||
|
|
||
| @Test | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should match
BitSetMethods's description: