Skip to content

Commit 345e18c

Browse files
committed
Avoid Iterator allocations when calling Sort.isSorted().
Closes #2445
1 parent cf33330 commit 345e18c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/main/java/org/springframework/data/domain/Sort.java

+9
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ public boolean isSorted() {
173173
return !isEmpty();
174174
}
175175

176+
@Override
177+
public boolean isEmpty() {
178+
return orders.isEmpty();
179+
}
180+
176181
public boolean isUnsorted() {
177182
return !isSorted();
178183
}
@@ -718,7 +723,11 @@ public Iterator<Order> iterator() {
718723
.map(Order::by) //
719724
.map(Collections::singleton) //
720725
.orElseGet(Collections::emptySet).iterator();
726+
}
721727

728+
@Override
729+
public boolean isEmpty() {
730+
return !recorded.getPropertyPath().isPresent();
722731
}
723732

724733
/*

src/main/java/org/springframework/data/querydsl/QSort.java

+5
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ private static Order toOrder(OrderSpecifier<?> orderSpecifier) {
104104
return Order.by(targetElement.toString()).with(orderSpecifier.isAscending() ? Direction.ASC : Direction.DESC);
105105
}
106106

107+
@Override
108+
public boolean isEmpty() {
109+
return orderSpecifiers.isEmpty();
110+
}
111+
107112
/**
108113
* @return the orderSpecifier
109114
*/

0 commit comments

Comments
 (0)