mirror of https://git.musl-libc.org/git/musl
Browse Source
we make qsort a wrapper by providing a wrapper_cmp function that uses the extra argument as a function pointer. should be optimized to a tail call on most architectures, as long as it's built with -fomit-frame-pointer, so the performance impact should be minimal. to keep the git history clean, for now qsort_r is implemented in qsort.c and qsort is implemented in qsort_nr.c. qsort.c also received a few trivial cleanups, including replacing (*cmp)() calls with cmp(). qsort_nr.c contains only wrapper_cmp and qsort as a qsort_r wrapper itself.master
committed by
Rich Felker
4 changed files with 36 additions and 17 deletions
@ -0,0 +1,14 @@ |
|||
#define _BSD_SOURCE |
|||
#include <stdlib.h> |
|||
|
|||
typedef int (*cmpfun)(const void *, const void *); |
|||
|
|||
static int wrapper_cmp(const void *v1, const void *v2, void *cmp) |
|||
{ |
|||
return ((cmpfun)cmp)(v1, v2); |
|||
} |
|||
|
|||
void qsort(void *base, size_t nel, size_t width, cmpfun cmp) |
|||
{ |
|||
__qsort_r(base, nel, width, wrapper_cmp, cmp); |
|||
} |
|||
Loading…
Reference in new issue