[llvm] 7dec464 - [ADT] Simplify llvm::sort with constexpr if (NFC)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 20 09:34:50 PDT 2022


Author: Kazu Hirata
Date: 2022-08-20T09:34:36-07:00
New Revision: 7dec4648c4f81c7ec0e118599c5ee87512092c21

URL: https://github.com/llvm/llvm-project/commit/7dec4648c4f81c7ec0e118599c5ee87512092c21
DIFF: https://github.com/llvm/llvm-project/commit/7dec4648c4f81c7ec0e118599c5ee87512092c21.diff

LOG: [ADT] Simplify llvm::sort with constexpr if (NFC)

Differential Revision: https://reviews.llvm.org/D132305

Added: 
    

Modified: 
    llvm/include/llvm/ADT/STLExtras.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index ae8231a2bc9c..4a72e9be2b5b 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -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) {


        


More information about the llvm-commits mailing list