Skip to content
Snippets Groups Projects
Unverified Commit f5ded007 authored by Alex Lyon's avatar Alex Lyon
Browse files

stdlib: recurse into the smaller partition when sorting

parent 4d3ac1c0
No related branches found
No related tags found
No related merge requests found
...@@ -46,10 +46,17 @@ fn introsort_helper( ...@@ -46,10 +46,17 @@ fn introsort_helper(
break; break;
} else { } else {
let (left, right) = partition(base, nel, width, comp); let (left, right) = partition(base, nel, width, comp);
introsort_helper(base, left, width, maxdepth, comp); let right_base = unsafe { base.add((right + 1) * width) };
base = unsafe { base.add((right + 1) * width) }; let right_nel = nel - (right + 1);
nel -= right + 1;
maxdepth -= 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;
}
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment