Skip to content

Commit c4454a5

Browse files
author
Stjepan Glavina
committed
Tweak the constants a bit
1 parent 942173b commit c4454a5

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/libcollections/slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,9 +1668,9 @@ fn merge_sort<T, F>(v: &mut [T], mut is_less: F)
16681668
where F: FnMut(&T, &T) -> bool
16691669
{
16701670
// Slices of up to this length get sorted using insertion sort.
1671-
const MAX_INSERTION: usize = 16;
1671+
const MAX_INSERTION: usize = 20;
16721672
// Very short runs are extended using insertion sort to span at least this many elements.
1673-
const MIN_RUN: usize = 8;
1673+
const MIN_RUN: usize = 10;
16741674

16751675
// Sorting has no meaningful behavior on zero-sized types.
16761676
if size_of::<T>() == 0 {

src/libcore/slice/sort.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ fn partition<T, F>(v: &mut [T], pivot: usize, is_less: &mut F) -> (usize, bool)
355355
l += 1;
356356
}
357357

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

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

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

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

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

0 commit comments

Comments
 (0)