Skip to content

Commit 594c4a5

Browse files
committed
linear search instead of binary search, unwrap() instead of expect()
Linear search should be more performant than binary search for all reasonable use cases (never more than 30 dimensions). Removed the expect() because it will add dedicated panic and printing code that should never execute.
1 parent bc9d0a2 commit 594c4a5

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/dimension.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ fn fastest_varying_order<D: Dimension>(strides: &D) -> D
2727
let mut sorted = strides.clone();
2828
sorted.slice_mut().sort();
2929
let mut res = strides.clone();
30-
for (ind, val) in strides.slice().iter().enumerate() {
31-
// cannot binary search in unsorted...
30+
for (ind, &val) in strides.slice().iter().enumerate() {
3231
let sorted_ind = sorted.slice()
33-
.binary_search(val)
34-
.expect("should be present");
32+
.iter()
33+
.enumerate()
34+
.find(|&(_, &x)| x == val)
35+
.unwrap().0; // cannot panic by construction
3536
res.slice_mut()[sorted_ind] = ind;
3637
}
3738
res

0 commit comments

Comments
 (0)