]> git.lizzy.rs Git - rust.git/commitdiff
memrchr: Use a conditional instead of subtracting a complicated min
authorUlrik Sverdrup <bluss@users.noreply.github.com>
Wed, 24 Aug 2016 19:41:23 +0000 (21:41 +0200)
committerUlrik Sverdrup <bluss@users.noreply.github.com>
Wed, 24 Aug 2016 19:41:23 +0000 (21:41 +0200)
This makes the critical calculation easier to understand.

src/libstd/memchr.rs

index 89b77a7d6614e8a6d72d7638ef06a9938699af0b..03f55f7ad61864cf3ed90ed794b36e41728873c0 100644 (file)
@@ -209,7 +209,7 @@ pub fn memrchr(x: u8, text: &[u8]) -> Option<usize> {
         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);
             }