Skip to content

Commit

Permalink
Tweak the constants a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Stjepan Glavina committed Mar 21, 2017
1 parent 942173b commit c4454a5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/libcollections/slice.rs
Expand Up @@ -1668,9 +1668,9 @@ fn merge_sort<T, F>(v: &mut [T], mut is_less: F)
where F: FnMut(&T, &T) -> bool
{
// Slices of up to this length get sorted using insertion sort.
const MAX_INSERTION: usize = 16;
const MAX_INSERTION: usize = 20;
// Very short runs are extended using insertion sort to span at least this many elements.
const MIN_RUN: usize = 8;
const MIN_RUN: usize = 10;

// Sorting has no meaningful behavior on zero-sized types.
if size_of::<T>() == 0 {
Expand Down
10 changes: 5 additions & 5 deletions src/libcore/slice/sort.rs
Expand Up @@ -355,7 +355,7 @@ fn partition<T, F>(v: &mut [T], pivot: usize, is_less: &mut F) -> (usize, bool)
l += 1;
}

// Find the last element lesser that the pivot.
// Find the last element smaller that the pivot.
while l < r && !is_less(v.get_unchecked(r - 1), pivot) {
r -= 1;
}
Expand Down Expand Up @@ -472,7 +472,7 @@ fn choose_pivot<T, F>(v: &mut [T], is_less: &mut F) -> (usize, bool)
{
// Minimal length to choose the median-of-medians method.
// Shorter slices use the simple median-of-three method.
const SHORTEST_MEDIAN_OF_MEDIANS: usize = 90;
const SHORTEST_MEDIAN_OF_MEDIANS: usize = 80;
// Maximal number of swaps that can be performed in this function.
const MAX_SWAPS: usize = 4 * 3;

Expand Down Expand Up @@ -539,7 +539,7 @@ fn recurse<'a, T, F>(mut v: &'a mut [T], is_less: &mut F, mut pred: Option<&'a T
where F: FnMut(&T, &T) -> bool
{
// Slices of up to this length get sorted using insertion sort.
const MAX_INSERTION: usize = 16;
const MAX_INSERTION: usize = 20;

// True if the last partitioning was reasonably balanced.
let mut was_balanced = true;
Expand Down Expand Up @@ -627,8 +627,8 @@ pub fn quicksort<T, F>(v: &mut [T], mut is_less: F)
return;
}

// Limit the number of imbalanced partitions to `floor(log2(len)) + 2`.
let limit = mem::size_of::<usize>() * 8 - v.len().leading_zeros() as usize + 1;
// Limit the number of imbalanced partitions to `floor(log2(len)) + 1`.
let limit = mem::size_of::<usize>() * 8 - v.len().leading_zeros() as usize;

recurse(v, &mut is_less, None, limit);
}

0 comments on commit c4454a5

Please sign in to comment.