|
9 | 9 | use crate::mem::{self, SizedTypeProperties}; |
10 | 10 | #[cfg(not(feature = "optimize_for_size"))] |
11 | 11 | use crate::slice::sort::shared::pivot::choose_pivot; |
12 | | -#[cfg(not(feature = "optimize_for_size"))] |
13 | 12 | use crate::slice::sort::shared::smallsort::insertion_sort_shift_left; |
14 | 13 | use crate::slice::sort::unstable::quicksort::partition; |
15 | 14 |
|
@@ -176,13 +175,7 @@ fn median_of_medians<T, F: FnMut(&T, &T) -> bool>(mut v: &mut [T], is_less: &mut |
176 | 175 | loop { |
177 | 176 | if v.len() <= INSERTION_SORT_THRESHOLD { |
178 | 177 | if v.len() >= 2 { |
179 | | - cfg_if! { |
180 | | - if #[cfg(feature = "optimize_for_size")] { |
181 | | - bubble_sort(v, is_less); |
182 | | - } else { |
183 | | - insertion_sort_shift_left(v, 1, is_less); |
184 | | - } |
185 | | - } |
| 178 | + insertion_sort_shift_left(v, 1, is_less); |
186 | 179 | } |
187 | 180 |
|
188 | 181 | return; |
@@ -314,35 +307,3 @@ fn median_idx<T, F: FnMut(&T, &T) -> bool>( |
314 | 307 | } |
315 | 308 | b |
316 | 309 | } |
317 | | - |
318 | | -// It's possible to re-use the insertion sort in the smallsort module, but with optimize_for_size it |
319 | | -// would clutter that module with cfg statements and make it generally harder to read and develop. |
320 | | -// So to decouple things and simplify it, we use an even smaller bubble sort. |
321 | | -#[cfg(feature = "optimize_for_size")] |
322 | | -fn bubble_sort<T, F: FnMut(&T, &T) -> bool>(v: &mut [T], is_less: &mut F) { |
323 | | - use crate::ptr; |
324 | | - |
325 | | - let mut n = v.len(); |
326 | | - |
327 | | - let v_base = v.as_mut_ptr(); |
328 | | - |
329 | | - while n > 1 { |
330 | | - let loop_n = n; |
331 | | - n = 0; |
332 | | - for i in 1..loop_n { |
333 | | - // SAFETY: The loop construction implies that `i` and `i - 1` will always be in-bounds. |
334 | | - unsafe { |
335 | | - // Even if `is_less` erroneously always returns true, we are guaranteed that `n` |
336 | | - // reduces by one each out loop iteration, because `1..n` is exclusive. This |
337 | | - // guarantees a bounded run-time should `Ord` be implemented incorrectly. |
338 | | - let v_i = v_base.add(i); |
339 | | - let v_i_minus_one = v_base.add(i - 1); |
340 | | - |
341 | | - if is_less(&*v_i, &*v_i_minus_one) { |
342 | | - ptr::swap_nonoverlapping(v_i, v_i_minus_one, 1); |
343 | | - n = i; |
344 | | - } |
345 | | - } |
346 | | - } |
347 | | - } |
348 | | -} |
0 commit comments