Skip to content

Commit ef8f3e9

Browse files
committed
libkern: Drop incorrect qsort optimization
See 5205b32 for details. PR: 287089 MFC after: 1 week Reviewed by: jlduran Differential Revision: https://reviews.freebsd.org/D51919
1 parent 6118587 commit ef8f3e9

File tree

1 file changed

+1
-13
lines changed

1 file changed

+1
-13
lines changed

sys/libkern/qsort.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,10 @@ qsort(void *a, size_t n, size_t es, cmp_t *cmp)
114114
char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
115115
size_t d1, d2;
116116
int cmp_result;
117-
int swaptype_long, swaptype_int, swap_cnt;
117+
int swaptype_long, swaptype_int;
118118

119119
loop: SWAPINIT(long, a, es);
120120
SWAPINIT(int, a, es);
121-
swap_cnt = 0;
122121
if (n < 7) {
123122
for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
124123
for (pl = pm;
@@ -147,15 +146,13 @@ loop: SWAPINIT(long, a, es);
147146
for (;;) {
148147
while (pb <= pc && (cmp_result = CMP(thunk, pb, a)) <= 0) {
149148
if (cmp_result == 0) {
150-
swap_cnt = 1;
151149
swap(pa, pb);
152150
pa += es;
153151
}
154152
pb += es;
155153
}
156154
while (pb <= pc && (cmp_result = CMP(thunk, pc, a)) >= 0) {
157155
if (cmp_result == 0) {
158-
swap_cnt = 1;
159156
swap(pc, pd);
160157
pd -= es;
161158
}
@@ -164,18 +161,9 @@ loop: SWAPINIT(long, a, es);
164161
if (pb > pc)
165162
break;
166163
swap(pb, pc);
167-
swap_cnt = 1;
168164
pb += es;
169165
pc -= es;
170166
}
171-
if (swap_cnt == 0) { /* Switch to insertion sort */
172-
for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
173-
for (pl = pm;
174-
pl > (char *)a && CMP(thunk, pl - es, pl) > 0;
175-
pl -= es)
176-
swap(pl, pl - es);
177-
return;
178-
}
179167

180168
pn = (char *)a + n * es;
181169
d1 = MIN(pa - (char *)a, pb - pa);

0 commit comments

Comments
 (0)