diff options
| author | Lzu Tao <taolzu@gmail.com> | 2020-07-13 09:35:10 +0000 |
|---|---|---|
| committer | Lzu Tao <taolzu@gmail.com> | 2020-07-28 03:16:55 +0000 |
| commit | 34c343ac27c519350577bd1bfdc4d1a3b90e6db6 (patch) | |
| tree | 5eec43448b0021dd7edee3f6bbcf91decdde9355 /library/std/src/sys | |
| parent | a5d0c2c17482e56cae5112083207e8c0ce19cb96 (diff) | |
| download | rust-34c343ac27c519350577bd1bfdc4d1a3b90e6db6.tar.gz rust-34c343ac27c519350577bd1bfdc4d1a3b90e6db6.zip | |
Make use of macro to avoid repetition
Diffstat (limited to 'library/std/src/sys')
| -rw-r--r-- | library/std/src/sys/windows/mod.rs | 33 |
1 files changed, 10 insertions, 23 deletions
diff --git a/library/std/src/sys/windows/mod.rs b/library/std/src/sys/windows/mod.rs index 3d155a8c8f0..ef4041e92d7 100644 --- a/library/std/src/sys/windows/mod.rs +++ b/library/std/src/sys/windows/mod.rs @@ -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..]; } |
