-
-
Notifications
You must be signed in to change notification settings - Fork 79
#1933 remove use of sun.misc.Unsafe #1934
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
base: main
Are you sure you want to change the base?
Conversation
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferences |
2530f6a
to
9d158fb
Compare
It looks good to me! |
bc5db5a
to
6a0f578
Compare
final long rw = theUnsafe.getLong(right, BYTE_ARRAY_BASE_OFFSET + (long) i); | ||
if (lw != rw) | ||
return false; | ||
try (Arena arena = Arena.ofConfined()) { |
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.
If you're using MemorySegments, I think this code could be simplified (and likely doesn't need the Arena
given these are heap allocated JVM arrays):
// assumes left and right are non-null and length is non-zero
if (left.length < length || right.length < length) return false;
MemorySegment leftSegment = MemorySegment.ofArray(left).asSlice(0, length);
MemorySegment rightSegment = MemorySegment.ofArray(right).asSlice(0, length);
// mismatch is optimized and should be faster than a for loop
return leftSegment.mismatch(rightSegment) == -1;
Compare needs to take into account the possibility that left or right is a prefix of the other, but would use the same general flow:
// assumes left and right are non-null
MemorySegment leftSegment = MemorySegment.ofArray(left);
MemorySegment rightSegment = MemorySegment.ofArray(right);
long index = leftSegment.mismatch(rightSegment);
if (index == -1) {
return Integer.compare(left.length, right.length);
}
// index is either the byte offset which differs or the length of the shorter array
if (index >= left.length || index >= right.length) {
return Integer.compare(left.length, right.length);
}
return Integer.compare(Byte.toUnsignedInt(left[(int)index]), Byte.toUnsignedInt(right[(int)index]));
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.
Wow, thank you!
…e of Arena and optimizing comparison logic
6a0f578
to
fb4c355
Compare
What does this PR do?
removes the use sun.mis.Unsafe
Motivation
Unsafe will be removed
Related issues
#1933
Checklist
mvn clean package
command