Draft
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
lvca
approved these changes
Jul 4, 2025
Contributor
|
It looks good to me! |
bc5db5a to
6a0f578
Compare
watford-ep
reviewed
Aug 1, 2025
| 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.
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]));…e of Arena and optimizing comparison logic
6a0f578 to
fb4c355
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
removes the use sun.mis.Unsafe
Motivation
Unsafe will be removed
Related issues
#1933
Checklist
mvn clean packagecommand