diff options
author | millert <> | 2017-05-30 14:54:09 +0000 |
---|---|---|
committer | millert <> | 2017-05-30 14:54:09 +0000 |
commit | c7a90a9a9d14e68354d14eaad525da1cc2a919f4 (patch) | |
tree | f6b619af24e90b0f0ced0c880a4a640857df903f /src | |
parent | 5d6e7d3a6ae121b3beb65f8adb80e5716ad60b15 (diff) | |
download | openbsd-c7a90a9a9d14e68354d14eaad525da1cc2a919f4.tar.gz openbsd-c7a90a9a9d14e68354d14eaad525da1cc2a919f4.tar.bz2 openbsd-c7a90a9a9d14e68354d14eaad525da1cc2a919f4.zip |
Don't fall back to heapsort() if we would otherwise switch to
insertion sort (when the number of elements is < 7).
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libc/stdlib/qsort.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/lib/libc/stdlib/qsort.c b/src/lib/libc/stdlib/qsort.c index 58f2ec4709..ca73e67f29 100644 --- a/src/lib/libc/stdlib/qsort.c +++ b/src/lib/libc/stdlib/qsort.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: qsort.c,v 1.17 2017/05/24 21:18:25 millert Exp $ */ | 1 | /* $OpenBSD: qsort.c,v 1.18 2017/05/30 14:54:09 millert Exp $ */ |
2 | /*- | 2 | /*- |
3 | * Copyright (c) 1992, 1993 | 3 | * Copyright (c) 1992, 1993 |
4 | * The Regents of the University of California. All rights reserved. | 4 | * The Regents of the University of California. All rights reserved. |
@@ -129,18 +129,18 @@ introsort(char *a, size_t n, size_t es, size_t maxdepth, int swaptype, | |||
129 | int cmp_result; | 129 | int cmp_result; |
130 | size_t r, s; | 130 | size_t r, s; |
131 | 131 | ||
132 | loop: if (maxdepth == 0) { | 132 | loop: if (n < 7) { |
133 | if (heapsort(a, n, es, cmp) == 0) | ||
134 | return; | ||
135 | } | ||
136 | maxdepth--; | ||
137 | if (n < 7) { | ||
138 | for (pm = a + es; pm < a + n * es; pm += es) | 133 | for (pm = a + es; pm < a + n * es; pm += es) |
139 | for (pl = pm; pl > a && cmp(pl - es, pl) > 0; | 134 | for (pl = pm; pl > a && cmp(pl - es, pl) > 0; |
140 | pl -= es) | 135 | pl -= es) |
141 | swap(pl, pl - es); | 136 | swap(pl, pl - es); |
142 | return; | 137 | return; |
143 | } | 138 | } |
139 | if (maxdepth == 0) { | ||
140 | if (heapsort(a, n, es, cmp) == 0) | ||
141 | return; | ||
142 | } | ||
143 | maxdepth--; | ||
144 | pm = a + (n / 2) * es; | 144 | pm = a + (n / 2) * es; |
145 | if (n > 7) { | 145 | if (n > 7) { |
146 | pl = a; | 146 | pl = a; |