Skip to content

Commit

Permalink
eclipse-rdf4jGH-2861 code cleanup in Sort
Browse files Browse the repository at this point in the history
Signed-off-by: Håvard Ottestad <[email protected]>
  • Loading branch information
hmottestad authored and RedCrusaderJr committed Apr 15, 2021
1 parent d14a183 commit 839eaca
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ private void sortTuples() {
while (iterator.hasNext()) {
ValidationTuple next = iterator.next();
sortedTuples.add(next);

// quick break out if sortedTuples is guaranteed to be of size 1 since we don't need to sort it
// then
if (sortedTuples.size() == 1 && !iterator.hasNext()) {
sortedTuplesIterator = sortedTuples.iterator();
return;
}

if (prev != null
&& prev.compareActiveTarget(next) > 0) {
alreadySorted = false;
Expand All @@ -89,12 +97,10 @@ private void sortTuples() {
if (!alreadySorted && sortedTuples.size() > 1) {
if (sortedTuples.size() > 8192) { // MIN_ARRAY_SORT_GRAN in Arrays.parallelSort(...)
ValidationTuple[] objects = sortedTuples.toArray(new ValidationTuple[0]);
Arrays.parallelSort(objects,
ValidationTuple::compareActiveTarget);
Arrays.parallelSort(objects, ValidationTuple::compareActiveTarget);
sortedTuples = Arrays.asList(objects);
} else {
sortedTuples
.sort(ValidationTuple::compareActiveTarget);
sortedTuples.sort(ValidationTuple::compareActiveTarget);
}
}
sortedTuplesIterator = sortedTuples.iterator();
Expand Down

0 comments on commit 839eaca

Please sign in to comment.