Skip to content

Commit 223385d

Browse files
authored
Fix unconditional panic warnings (#71)
We can just use `.get_unsafe()` here. Drive-by-fix: clippy warning. Drive-by-fix: clippy warning. Fixes #68.
1 parent 3578e32 commit 223385d

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/implementation/algorithm.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,21 +181,19 @@ macro_rules! algorithm_simd {
181181

182182
#[cfg_attr(not(target_arch="aarch64"), target_feature(enable = $feat))]
183183
#[inline]
184-
#[allow(unconditional_panic)] // does not panic because len is checked
185-
#[allow(const_err)] // the same, but for Rust 1.38.0
186184
unsafe fn check_block(&mut self, input: SimdInput) {
187185
// WORKAROUND
188186
// necessary because the for loop is not unrolled on ARM64
189187
if input.vals.len() == 2 {
190-
self.check_bytes(input.vals[0]);
191-
self.check_bytes(input.vals[1]);
192-
self.incomplete = Self::is_incomplete(input.vals[1]);
188+
self.check_bytes(*input.vals.get_unchecked(0));
189+
self.check_bytes(*input.vals.get_unchecked(1));
190+
self.incomplete = Self::is_incomplete(*input.vals.get_unchecked(1));
193191
} else if input.vals.len() == 4 {
194-
self.check_bytes(input.vals[0]);
195-
self.check_bytes(input.vals[1]);
196-
self.check_bytes(input.vals[2]);
197-
self.check_bytes(input.vals[3]);
198-
self.incomplete = Self::is_incomplete(input.vals[3]);
192+
self.check_bytes(*input.vals.get_unchecked(0));
193+
self.check_bytes(*input.vals.get_unchecked(1));
194+
self.check_bytes(*input.vals.get_unchecked(2));
195+
self.check_bytes(*input.vals.get_unchecked(3));
196+
self.incomplete = Self::is_incomplete(*input.vals.get_unchecked(3));
199197
} else {
200198
panic!("Unsupported number of chunks");
201199
}

src/implementation/helpers.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ pub(crate) fn get_compat_error(input: &[u8], failing_block_pos: usize) -> Utf8Er
3030
// UTF-8 codepoint, is thus complete and valid UTF-8. We start the check with the
3131
// current block in that case.
3232
(1..=3)
33-
.into_iter()
3433
.find(|i| input[failing_block_pos - i] >> 6 != 0b10)
3534
.map_or(failing_block_pos, |i| failing_block_pos - i)
3635
};

0 commit comments

Comments
 (0)