stdlib: recurse into the smaller partition when sorting

This commit is contained in:
Alex Lyon
2018-05-13 16:16:48 -07:00
parent 4d3ac1c0dc
commit f5ded007c6
+10 -3
View File
@@ -46,10 +46,17 @@ fn introsort_helper(
break;
} else {
let (left, right) = partition(base, nel, width, comp);
introsort_helper(base, left, width, maxdepth, comp);
base = unsafe { base.add((right + 1) * width) };
nel -= right + 1;
let right_base = unsafe { base.add((right + 1) * width) };
let right_nel = nel - (right + 1);
maxdepth -= 1;
if left < nel - right {
introsort_helper(base, left, width, maxdepth, comp);
base = right_base;
nel = right_nel;
} else {
introsort_helper(right_base, right_nel, width, maxdepth, comp);
nel = left;
}
}
}
}