diff options
| author | millert <> | 2017-05-30 14:54:09 +0000 |
|---|---|---|
| committer | millert <> | 2017-05-30 14:54:09 +0000 |
| commit | 9bb08519777cb36d56fcc2f3de3f9004de1b7361 (patch) | |
| tree | f6b619af24e90b0f0ced0c880a4a640857df903f | |
| parent | b4ca6599527e8767077c39409965f099aa3d3769 (diff) | |
| download | openbsd-9bb08519777cb36d56fcc2f3de3f9004de1b7361.tar.gz openbsd-9bb08519777cb36d56fcc2f3de3f9004de1b7361.tar.bz2 openbsd-9bb08519777cb36d56fcc2f3de3f9004de1b7361.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 '')
| -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; |
