Changing 'r' to a size_t in the previous commit turned quicksort
into slowsort for some sequences because different parts of the code used 'r' to store two different things, one of which was signed. Clean things up by splitting 'r' into two variables, and use a more meaningful name.
This commit is contained in:
parent
bd332c3c41
commit
00c36da743
@ -112,6 +112,7 @@ qsort(void *a, size_t n, size_t es, cmp_t *cmp)
|
||||
{
|
||||
char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
|
||||
size_t d, r;
|
||||
int cmp_result;
|
||||
int swaptype, swap_cnt;
|
||||
|
||||
loop: SWAPINIT(a, es);
|
||||
@ -141,16 +142,16 @@ loop: SWAPINIT(a, es);
|
||||
|
||||
pc = pd = (char *)a + (n - 1) * es;
|
||||
for (;;) {
|
||||
while (pb <= pc && (r = CMP(thunk, pb, a)) <= 0) {
|
||||
if (r == 0) {
|
||||
while (pb <= pc && (cmp_result = CMP(thunk, pb, a)) <= 0) {
|
||||
if (cmp_result == 0) {
|
||||
swap_cnt = 1;
|
||||
swap(pa, pb);
|
||||
pa += es;
|
||||
}
|
||||
pb += es;
|
||||
}
|
||||
while (pb <= pc && (r = CMP(thunk, pc, a)) >= 0) {
|
||||
if (r == 0) {
|
||||
while (pb <= pc && (cmp_result = CMP(thunk, pc, a)) >= 0) {
|
||||
if (cmp_result == 0) {
|
||||
swap_cnt = 1;
|
||||
swap(pc, pd);
|
||||
pd -= es;
|
||||
|
Loading…
Reference in New Issue
Block a user