[libc-commits] [libc] [llvm] [libc] Improve qsort (PR #120450)
Lukas Bergdoll via libc-commits
libc-commits at lists.llvm.org
Fri Dec 20 01:50:41 PST 2024
================
@@ -19,13 +19,11 @@ LLVM_LIBC_FUNCTION(void, qsort_r,
(void *array, size_t array_size, size_t elem_size,
int (*compare)(const void *, const void *, void *),
void *arg)) {
- if (array == nullptr || array_size == 0 || elem_size == 0)
- return;
- internal::Comparator c(compare, arg);
- auto arr = internal::Array(reinterpret_cast<uint8_t *>(array), array_size,
- elem_size, c);
- internal::sort(arr);
+ internal::unstable_sort(array, array_size, elem_size,
+ [compare, arg](const void *a, const void *b) -> bool {
+ return compare(a, b, arg) < 0;
+ });
----------------
Voultapher wrote:
I appreciate your concern about readability and like the idea of pulling out the comparison function to a named variable, will do.
https://github.com/llvm/llvm-project/pull/120450
More information about the libc-commits
mailing list