Skip to content

Commit 34c343a

Browse files
committed
Make use of macro to avoid repetition
1 parent a5d0c2c commit 34c343a

File tree

1 file changed

+10
-23
lines changed
  • library/std/src/sys/windows

1 file changed

+10
-23
lines changed

library/std/src/sys/windows/mod.rs

+10-23
Original file line numberDiff line numberDiff line change
@@ -103,31 +103,18 @@ pub fn unrolled_find_u16s(needle: u16, haystack: &[u16]) -> Option<usize> {
103103

104104
// For performance reasons unfold the loop eight times.
105105
while start.len() >= 8 {
106-
if start[0] == needle {
107-
return Some((start.as_ptr() as usize - ptr as usize) / 2);
108-
}
109-
if start[1] == needle {
110-
return Some((start[1..].as_ptr() as usize - ptr as usize) / 2);
111-
}
112-
if start[2] == needle {
113-
return Some((start[2..].as_ptr() as usize - ptr as usize) / 2);
114-
}
115-
if start[3] == needle {
116-
return Some((start[3..].as_ptr() as usize - ptr as usize) / 2);
117-
}
118-
if start[4] == needle {
119-
return Some((start[4..].as_ptr() as usize - ptr as usize) / 2);
120-
}
121-
if start[5] == needle {
122-
return Some((start[5..].as_ptr() as usize - ptr as usize) / 2);
123-
}
124-
if start[6] == needle {
125-
return Some((start[6..].as_ptr() as usize - ptr as usize) / 2);
126-
}
127-
if start[7] == needle {
128-
return Some((start[7..].as_ptr() as usize - ptr as usize) / 2);
106+
macro_rules! if_return {
107+
($($n:literal,)+) => {
108+
$(
109+
if start[$n] == needle {
110+
return Some((&start[$n] as *const u16 as usize - ptr as usize) / 2);
111+
}
112+
)+
113+
}
129114
}
130115

116+
if_return!(0, 1, 2, 3, 4, 5, 6, 7,);
117+
131118
start = &start[8..];
132119
}
133120

0 commit comments

Comments
 (0)