Skip to content

Commit

Permalink
Better codegen for memrchr fallback
Browse files Browse the repository at this point in the history
This rewriting to explicitly compute contains_zero_byte before the if,
allows the compiler to generate better code.
  • Loading branch information
bluss committed Aug 19, 2015
1 parent 9741001 commit 6a1b5d7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ mod fallback {

while offset >= 2 * USIZE_BYTES {
unsafe {
let mut u = *(ptr.offset(offset as isize - 2 * USIZE_BYTES as isize) as *const usize);
let mut v = *(ptr.offset(offset as isize - USIZE_BYTES as isize) as *const usize);
let u = *(ptr.offset(offset as isize - 2 * USIZE_BYTES as isize) as *const usize);
let v = *(ptr.offset(offset as isize - USIZE_BYTES as isize) as *const usize);

// break if there is a matching byte
u ^= repeated_x;
v ^= repeated_x;
if contains_zero_byte(u) || contains_zero_byte(v) {
let zu = contains_zero_byte(u ^ repeated_x);
let zv = contains_zero_byte(v ^ repeated_x);
if zu || zv {
break;
}
}
Expand Down

0 comments on commit 6a1b5d7

Please sign in to comment.