diff --git a/core/src/slice/sort/stable/mod.rs b/core/src/slice/sort/stable/mod.rs index 3472401c4dcf8..00eb3785e0f25 100644 --- a/core/src/slice/sort/stable/mod.rs +++ b/core/src/slice/sort/stable/mod.rs @@ -40,20 +40,27 @@ pub fn sort bool, BufT: BufGuard>(v: &mut [T], is_less } cfg_if! { - if #[cfg(feature = "optimize_for_size")] { + if #[cfg(any(feature = "optimize_for_size", target_pointer_width = "16"))] { let alloc_len = len / 2; - // For small inputs 4KiB of stack storage suffices, which allows us to avoid - // calling the (de-)allocator. Benchmarks showed this was quite beneficial. - let mut stack_buf = AlignedStorage::::new(); - let stack_scratch = stack_buf.as_uninit_slice_mut(); - let mut heap_buf; - let scratch = if stack_scratch.len() >= alloc_len { - stack_scratch - } else { - heap_buf = BufT::with_capacity(alloc_len); - heap_buf.as_uninit_slice_mut() - }; + cfg_if! { + if #[cfg(target_pointer_width = "16")] { + let heap_buf = BufT::with_capacity(alloc_len); + let scratch = heap_buf.as_uninit_slice_mut(); + } else { + // For small inputs 4KiB of stack storage suffices, which allows us to avoid + // calling the (de-)allocator. Benchmarks showed this was quite beneficial. + let mut stack_buf = AlignedStorage::::new(); + let stack_scratch = stack_buf.as_uninit_slice_mut(); + let mut heap_buf; + let scratch = if stack_scratch.len() >= alloc_len { + stack_scratch + } else { + heap_buf = BufT::with_capacity(alloc_len); + heap_buf.as_uninit_slice_mut() + }; + } + } tiny::mergesort(v, scratch, is_less); } else { diff --git a/core/src/slice/sort/unstable/mod.rs b/core/src/slice/sort/unstable/mod.rs index 953c27ab6f417..8bbd85443d478 100644 --- a/core/src/slice/sort/unstable/mod.rs +++ b/core/src/slice/sort/unstable/mod.rs @@ -31,7 +31,7 @@ pub fn sort bool>(v: &mut [T], is_less: &mut F) { } cfg_if! { - if #[cfg(feature = "optimize_for_size")] { + if #[cfg(any(feature = "optimize_for_size", target_pointer_width = "16"))] { heapsort::heapsort(v, is_less); } else { // More advanced sorting methods than insertion sort are faster if called in