Skip to content

Commit

Permalink
perf: Avoid a saturating add in slice_uncons_while
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Westerlind committed Jul 16, 2021
1 parent 7fcecad commit ad4180d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/stream/mod.rs
Expand Up @@ -629,6 +629,8 @@ where
{
let mut i = start as usize;
let len = slice.len();
// SAFETY: We only call this function with `One` if the slice has length >= 1
debug_assert!(len >= i, "");
let mut found = false;

macro_rules! check {
Expand All @@ -642,8 +644,7 @@ where
}

// SAFETY: ensures we can access at least 8 elements starting at i, making get_unchecked sound.
// uses saturating arith in case len=0, i=1
while len.saturating_sub(i) >= 8 {
while len - i >= 8 {
check!();
check!();
check!();
Expand Down

0 comments on commit ad4180d

Please sign in to comment.