| #include "git-compat-util.h" |
| * A merge sort implementation, simplified from the qsort implementation |
| * by Mike Haertel, which is a part of the GNU C Library. |
| static void msort_with_tmp(void *b, size_t n, size_t s, |
| int (*cmp)(const void *, const void *), |
| b2 = (char *)b + (n1 * s); |
| msort_with_tmp(b1, n1, s, cmp, t); |
| msort_with_tmp(b2, n2, s, cmp, t); |
| while (n1 > 0 && n2 > 0) { |
| memcpy(b, t, (n - n2) * s); |
| void git_stable_qsort(void *b, size_t n, size_t s, |
| int (*cmp)(const void *, const void *)) |
| const size_t size = st_mult(n, s); |
| msort_with_tmp(b, n, s, cmp, tmp); |