Skip to content

Commit

Permalink
[SPARK-36047][CORE] Replace the handwriting compare methods with stat…
Browse files Browse the repository at this point in the history
…ic compare methods in Java code

### What changes were proposed in this pull request?
The main change of this is use the static `Integer.compare()` method and `Long.compare()` method instead of the handwriting compare method in Java code.

### Why are the changes needed?
Removing unnecessary handwriting compare methods

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
Pass the Jenkins or GitHub Action

Closes #33260 from LuciferYang/static-compare.

Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: Sean Owen <srowen@gmail.com>
  • Loading branch information
LuciferYang authored and srowen committed Jul 10, 2021
1 parent f5a6332 commit 83b3b75
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Expand Up @@ -31,9 +31,7 @@ final class ShuffleInMemorySorter {
private static final class SortComparator implements Comparator<PackedRecordPointer> {
@Override
public int compare(PackedRecordPointer left, PackedRecordPointer right) {
int leftId = left.getPartitionId();
int rightId = right.getPartitionId();
return leftId < rightId ? -1 : (leftId > rightId ? 1 : 0);
return Integer.compare(left.getPartitionId(), right.getPartitionId());
}
}
private static final SortComparator SORT_COMPARATOR = new SortComparator();
Expand Down
Expand Up @@ -141,7 +141,7 @@ public static final class SignedPrefixComparator extends RadixSortSupport {
@Override public boolean sortSigned() { return true; }
@Override public boolean nullsFirst() { return true; }
public int compare(long a, long b) {
return (a < b) ? -1 : (a > b) ? 1 : 0;
return Long.compare(a, b);
}
}

Expand All @@ -150,7 +150,7 @@ public static final class SignedPrefixComparatorNullsLast extends RadixSortSuppo
@Override public boolean sortSigned() { return true; }
@Override public boolean nullsFirst() { return false; }
public int compare(long a, long b) {
return (a < b) ? -1 : (a > b) ? 1 : 0;
return Long.compare(a, b);
}
}

Expand All @@ -159,7 +159,7 @@ public static final class SignedPrefixComparatorDescNullsFirst extends RadixSort
@Override public boolean sortSigned() { return true; }
@Override public boolean nullsFirst() { return true; }
public int compare(long b, long a) {
return (a < b) ? -1 : (a > b) ? 1 : 0;
return Long.compare(a, b);
}
}

Expand All @@ -168,7 +168,7 @@ public static final class SignedPrefixComparatorDesc extends RadixSortSupport {
@Override public boolean sortSigned() { return true; }
@Override public boolean nullsFirst() { return false; }
public int compare(long b, long a) {
return (a < b) ? -1 : (a > b) ? 1 : 0;
return Long.compare(a, b);
}
}
}

0 comments on commit 83b3b75

Please sign in to comment.