Skip to content

Commit

Permalink
Make use of macro to avoid repetition
Browse files Browse the repository at this point in the history
  • Loading branch information
tesuji committed Jul 28, 2020
1 parent a5d0c2c commit 34c343a
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions library/std/src/sys/windows/mod.rs
Expand Up @@ -103,31 +103,18 @@ pub fn unrolled_find_u16s(needle: u16, haystack: &[u16]) -> Option<usize> {

// For performance reasons unfold the loop eight times.
while start.len() >= 8 {
if start[0] == needle {
return Some((start.as_ptr() as usize - ptr as usize) / 2);
}
if start[1] == needle {
return Some((start[1..].as_ptr() as usize - ptr as usize) / 2);
}
if start[2] == needle {
return Some((start[2..].as_ptr() as usize - ptr as usize) / 2);
}
if start[3] == needle {
return Some((start[3..].as_ptr() as usize - ptr as usize) / 2);
}
if start[4] == needle {
return Some((start[4..].as_ptr() as usize - ptr as usize) / 2);
}
if start[5] == needle {
return Some((start[5..].as_ptr() as usize - ptr as usize) / 2);
}
if start[6] == needle {
return Some((start[6..].as_ptr() as usize - ptr as usize) / 2);
}
if start[7] == needle {
return Some((start[7..].as_ptr() as usize - ptr as usize) / 2);
macro_rules! if_return {
($($n:literal,)+) => {
$(
if start[$n] == needle {
return Some((&start[$n] as *const u16 as usize - ptr as usize) / 2);
}
)+
}
}

if_return!(0, 1, 2, 3, 4, 5, 6, 7,);

start = &start[8..];
}

Expand Down

0 comments on commit 34c343a

Please sign in to comment.