[libc-commits] [libc] [llvm] [libc] Improve qsort (PR #120450)
Lukas Bergdoll via libc-commits
libc-commits at lists.llvm.org
Fri Dec 20 01:53:25 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;
+ });
----------------
Voultapher wrote:
Same argument as https://github.com/llvm/llvm-project/pull/120450#discussion_r1893719735 but arguably even more important since if we would call `quick_sort` directly we wouldn't test the Lomuto partition.
https://github.com/llvm/llvm-project/pull/120450
More information about the libc-commits
mailing list