From: Ulrik Sverdrup Date: Wed, 24 Aug 2016 19:41:23 +0000 (+0200) Subject: memrchr: Use a conditional instead of subtracting a complicated min X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=8295c5056da0be355c86b29d1d4eed469920e73c;p=rust.git memrchr: Use a conditional instead of subtracting a complicated min This makes the critical calculation easier to understand. --- diff --git a/src/libstd/memchr.rs b/src/libstd/memchr.rs index 89b77a7d661..03f55f7ad61 100644 --- a/src/libstd/memchr.rs +++ b/src/libstd/memchr.rs @@ -209,7 +209,7 @@ pub fn memrchr(x: u8, text: &[u8]) -> Option { let end_align = (ptr as usize + len) & (usize_bytes - 1); let mut offset; if end_align > 0 { - offset = len - cmp::min(end_align, len); + offset = if end_align >= len { 0 } else { len - end_align }; if let Some(index) = text[offset..].iter().rposition(|elt| *elt == x) { return Some(offset + index); }