@@ -39,40 +39,38 @@ pub fn sort<T, F: FnMut(&T, &T) -> bool, BufT: BufGuard<T>>(v: &mut [T], is_less
39
39
return ;
40
40
}
41
41
42
- #[ cfg( not( feature = "optimize_for_size" ) ) ]
43
- {
44
- // More advanced sorting methods than insertion sort are faster if called in
45
- // a hot loop for small inputs, but for general-purpose code the small
46
- // binary size of insertion sort is more important. The instruction cache in
47
- // modern processors is very valuable, and for a single sort call in general
48
- // purpose code any gains from an advanced method are cancelled by i-cache
49
- // misses during the sort, and thrashing the i-cache for surrounding code.
50
- const MAX_LEN_ALWAYS_INSERTION_SORT : usize = 20 ;
51
- if intrinsics:: likely ( len <= MAX_LEN_ALWAYS_INSERTION_SORT ) {
52
- insertion_sort_shift_left ( v, 1 , is_less) ;
53
- return ;
54
- }
55
-
56
- driftsort_main :: < T , F , BufT > ( v, is_less) ;
57
- }
58
-
59
- #[ cfg( feature = "optimize_for_size" ) ]
60
- {
61
- let alloc_len = len / 2 ;
62
-
63
- // For small inputs 4KiB of stack storage suffices, which allows us to avoid
64
- // calling the (de-)allocator. Benchmarks showed this was quite beneficial.
65
- let mut stack_buf = AlignedStorage :: < T , 4096 > :: new ( ) ;
66
- let stack_scratch = stack_buf. as_uninit_slice_mut ( ) ;
67
- let mut heap_buf;
68
- let scratch = if stack_scratch. len ( ) >= alloc_len {
69
- stack_scratch
42
+ cfg_if ! {
43
+ if #[ cfg( feature = "optimize_for_size" ) ] {
44
+ let alloc_len = len / 2 ;
45
+
46
+ // For small inputs 4KiB of stack storage suffices, which allows us to avoid
47
+ // calling the (de-)allocator. Benchmarks showed this was quite beneficial.
48
+ let mut stack_buf = AlignedStorage :: <T , 4096 >:: new( ) ;
49
+ let stack_scratch = stack_buf. as_uninit_slice_mut( ) ;
50
+ let mut heap_buf;
51
+ let scratch = if stack_scratch. len( ) >= alloc_len {
52
+ stack_scratch
53
+ } else {
54
+ heap_buf = BufT :: with_capacity( alloc_len) ;
55
+ heap_buf. as_uninit_slice_mut( )
56
+ } ;
57
+
58
+ tiny:: mergesort( v, scratch, is_less) ;
70
59
} else {
71
- heap_buf = BufT :: with_capacity ( alloc_len) ;
72
- heap_buf. as_uninit_slice_mut ( )
73
- } ;
74
-
75
- tiny:: mergesort ( v, scratch, is_less) ;
60
+ // More advanced sorting methods than insertion sort are faster if called in
61
+ // a hot loop for small inputs, but for general-purpose code the small
62
+ // binary size of insertion sort is more important. The instruction cache in
63
+ // modern processors is very valuable, and for a single sort call in general
64
+ // purpose code any gains from an advanced method are cancelled by i-cache
65
+ // misses during the sort, and thrashing the i-cache for surrounding code.
66
+ const MAX_LEN_ALWAYS_INSERTION_SORT : usize = 20 ;
67
+ if intrinsics:: likely( len <= MAX_LEN_ALWAYS_INSERTION_SORT ) {
68
+ insertion_sort_shift_left( v, 1 , is_less) ;
69
+ return ;
70
+ }
71
+
72
+ driftsort_main:: <T , F , BufT >( v, is_less) ;
73
+ }
76
74
}
77
75
}
78
76
0 commit comments