pub fn unrolled_find_u16s(needle: u16, haystack: &[u16]) -> Option<usize> {
let ptr = haystack.as_ptr();
- let mut len = haystack.len();
let mut start = &haystack[..];
// For performance reasons unfold the loop eight times.
- while 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);
+ while start.len() >= 8 {
+ 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..];
- len -= 8;
}
- for (i, c) in start.iter().enumerate() {
+ for c in start {
if *c == needle {
- return Some((start.as_ptr() as usize - ptr as usize) / 2 + i);
+ return Some((c as *const u16 as usize - ptr as usize) / 2);
}
}
None
.unwrap_or(c::INFINITE)
}
-// On Windows, use the processor-specific __fastfail mechanism. In Windows 8
-// and later, this will terminate the process immediately without running any
-// in-process exception handlers. In earlier versions of Windows, this
-// sequence of instructions will be treated as an access violation,
-// terminating the process but without necessarily bypassing all exception
-// handlers.
-//
-// https://docs.microsoft.com/en-us/cpp/intrinsics/fastfail
+/// Use `__fastfail` to abort the process
+///
+/// This is the same implementation as in libpanic_abort's `__rust_start_panic`. See
+/// that function for more information on `__fastfail`
#[allow(unreachable_code)]
pub fn abort_internal() -> ! {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]