Skip to content

Commit 40b32c6

Browse files
Folkert de Vriesfolkertdev
authored andcommitted
specialize rotate_right by 1
1 parent 4d1750f commit 40b32c6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

libbz2-rs-sys/src/decompress.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ pub(crate) fn decompress(
10191019

10201020
let mut pos: [u8; 6] = [0, 1, 2, 3, 4, 5];
10211021
for i in 0..usize::from(nSelectors) {
1022-
pos[..=usize::from(s.selectorMtf[i])].rotate_right(1);
1022+
rotate_right_1(&mut pos[..=usize::from(s.selectorMtf[i])]);
10231023
s.selector[i] = pos[0];
10241024
}
10251025

@@ -1232,7 +1232,7 @@ fn initialize_mtfa(mtfa: &mut [u8; 4096], mtfbase: &mut [u16; 16], nextSym: u16)
12321232
// avoid general case expense
12331233
let pp = usize::from(mtfbase[0]);
12341234
let uc = mtfa[pp + nn];
1235-
mtfa[pp..][..=nn].rotate_right(1);
1235+
rotate_right_1(&mut mtfa[pp..][..=nn]);
12361236

12371237
uc
12381238
} else {
@@ -1268,3 +1268,10 @@ fn initialize_mtfa(mtfa: &mut [u8; 4096], mtfbase: &mut [u16; 16], nextSym: u16)
12681268
uc
12691269
}
12701270
}
1271+
1272+
fn rotate_right_1(slice: &mut [u8]) {
1273+
let Some(&last) = slice.last() else { return };
1274+
1275+
slice.copy_within(0..slice.len() - 1, 1);
1276+
slice[0] = last;
1277+
}

0 commit comments

Comments
 (0)