From d7cf184d2dd37ac6aa6ef98161e089e7b476d29e Mon Sep 17 00:00:00 2001 From: Tommaso Fontana Date: Tue, 14 Jan 2025 18:39:40 +0100 Subject: [PATCH] In partia_insertion-sort, moved the SHORTEST_SHIFTING check outside of loop While the compiler probably optimizes this, it was confusing to read. --- src/slice/sort.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/slice/sort.rs b/src/slice/sort.rs index 88fb9ff8a..9f1584c81 100644 --- a/src/slice/sort.rs +++ b/src/slice/sort.rs @@ -223,6 +223,11 @@ where let len = v.len(); let mut i = 1; + // Don't shift elements on short arrays, that has a performance cost. + if len < SHORTEST_SHIFTING { + return false; + } + for _ in 0..MAX_STEPS { // SAFETY: We already explicitly did the bound checking with `i < len`. // All our subsequent indexing is only in the range `0 <= index < len` @@ -238,11 +243,6 @@ where return true; } - // Don't shift elements on short arrays, that has a performance cost. - if len < SHORTEST_SHIFTING { - return false; - } - // Swap the found pair of elements. This puts them in correct order. v.swap(i - 1, i);