Skip to content

Commit

Permalink
nano-optimization for memchr::repeat_byte
Browse files Browse the repository at this point in the history
  • Loading branch information
llogiq committed May 2, 2018
1 parent 3eadd75 commit 1cefb5c
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions src/libcore/slice/memchr.rs
Expand Up @@ -39,21 +39,10 @@ fn repeat_byte(b: u8) -> usize {
(b as usize) << 8 | b as usize
}

#[cfg(target_pointer_width = "32")]
#[cfg(not(target_pointer_width = "16"))]
#[inline]
fn repeat_byte(b: u8) -> usize {
let mut rep = (b as usize) << 8 | b as usize;
rep = rep << 16 | rep;
rep
}

#[cfg(target_pointer_width = "64")]
#[inline]
fn repeat_byte(b: u8) -> usize {
let mut rep = (b as usize) << 8 | b as usize;
rep = rep << 16 | rep;
rep = rep << 32 | rep;
rep
(b as usize) * (::usize::MAX / 255)
}

/// Return the first index matching the byte `x` in `text`.
Expand Down

0 comments on commit 1cefb5c

Please sign in to comment.