Skip to content

Commit

Permalink
[ADT] Simplify llvm::sort with constexpr if (NFC)
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D132305
  • Loading branch information
kazutakahirata committed Aug 20, 2022
1 parent abb6271 commit 7dec464
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions llvm/include/llvm/ADT/STLExtras.h
Expand Up @@ -1548,23 +1548,18 @@ using sort_trivially_copyable = std::conjunction<

// Provide wrappers to std::sort which shuffle the elements before sorting
// to help uncover non-deterministic behavior (PR35135).
template <typename IteratorTy,
std::enable_if_t<!detail::sort_trivially_copyable<IteratorTy>::value,
int> = 0>
template <typename IteratorTy>
inline void sort(IteratorTy Start, IteratorTy End) {
if constexpr (detail::sort_trivially_copyable<IteratorTy>::value) {
// Forward trivially copyable types to array_pod_sort. This avoids a large
// amount of code bloat for a minor performance hit.
array_pod_sort(Start, End);
} else {
#ifdef EXPENSIVE_CHECKS
detail::presortShuffle<IteratorTy>(Start, End);
detail::presortShuffle<IteratorTy>(Start, End);
#endif
std::sort(Start, End);
}

// Forward trivially copyable types to array_pod_sort. This avoids a large
// amount of code bloat for a minor performance hit.
template <typename IteratorTy,
std::enable_if_t<detail::sort_trivially_copyable<IteratorTy>::value,
int> = 0>
inline void sort(IteratorTy Start, IteratorTy End) {
array_pod_sort(Start, End);
std::sort(Start, End);
}
}

template <typename Container> inline void sort(Container &&C) {
Expand Down

0 comments on commit 7dec464

Please sign in to comment.