[libc] [llvm] [libc] Improve qsort (PR #120450)

Michael Jones via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 19 13:13:34 PST 2024


================
@@ -7,10 +7,17 @@
 //===----------------------------------------------------------------------===//
 
 #include "SortingTest.h"
-#include "src/stdlib/quick_sort.h"
+#include "src/stdlib/qsort_util.h"
 
-void sort(const LIBC_NAMESPACE::internal::Array &array) {
-  LIBC_NAMESPACE::internal::quick_sort(array);
+void quick_sort(void *array, size_t array_size, size_t elem_size,
+                int (*compare)(const void *, const void *)) {
+  constexpr bool USE_QUICKSORT = true;
+
+  LIBC_NAMESPACE::internal::unstable_sort_impl<USE_QUICKSORT>(
+      array, array_size, elem_size,
+      [compare](const void *a, const void *b) noexcept -> bool {
+        return compare(a, b) < 0;
+      });
----------------
michaelrj-google wrote:

why not call quicksort directly?

https://github.com/llvm/llvm-project/pull/120450


More information about the llvm-commits mailing list