diff options
Diffstat (limited to 'stdlib/qsort.c')
-rw-r--r-- | stdlib/qsort.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/stdlib/qsort.c b/stdlib/qsort.c index 10b805930a..3f78b66bc8 100644 --- a/stdlib/qsort.c +++ b/stdlib/qsort.c @@ -100,14 +100,24 @@ typedef struct #define POP(low, high) ((void) (--top, (low = top->lo), (high = top->hi))) #define STACK_NOT_EMPTY (stack < top) +/* Helper function to calculate the maximum depth before quicksort switches + to heapsort. X should be higher than 0. */ +static inline size_t +lg (size_t x) +{ + return sizeof (size_t) * CHAR_BIT - 1 - __builtin_clzl(x); +} + #define R_VERSION #define R_FUNC __qsort_r +#define R_HEAP heapsort_r #include <stdlib/qsort_common.c> libc_hidden_def (__qsort_r) weak_alias (__qsort_r, qsort_r) #define R_FUNC qsort +#define R_HEAP heapsort #include <stdlib/qsort_common.c> libc_hidden_def (qsort) |