pub fn memrchr2(n1: u8, n2: u8, haystack: &[u8]) -> Option<usize> {
    let vn1 = repeat_byte(n1);
    let vn2 = repeat_byte(n2);
    let confirm = |byte| byte == n1 || byte == n2;
    let align = USIZE_BYTES - 1;
    let start_ptr = haystack.as_ptr();

    unsafe {
        let end_ptr = start_ptr.add(haystack.len());
        let mut ptr = end_ptr;
        if haystack.len() < USIZE_BYTES {
            return reverse_search(start_ptr, end_ptr, ptr, confirm);
        }

        let chunk = (ptr.sub(USIZE_BYTES) as *const usize).read_unaligned();
        let eq1 = contains_zero_byte(chunk ^ vn1);
        let eq2 = contains_zero_byte(chunk ^ vn2);
        if eq1 || eq2 {
            return reverse_search(start_ptr, end_ptr, ptr, confirm);
        }

        ptr = (end_ptr as usize & !align) as *const u8;
        debug_assert!(start_ptr <= ptr && ptr <= end_ptr);
        while ptr >= start_ptr.add(USIZE_BYTES) {
            debug_assert_eq!(0, (ptr as usize) % USIZE_BYTES);

            let chunk = *(ptr.sub(USIZE_BYTES) as *const usize);
            let eq1 = contains_zero_byte(chunk ^ vn1);
            let eq2 = contains_zero_byte(chunk ^ vn2);
            if eq1 || eq2 {
                break;
            }
            ptr = ptr.sub(USIZE_BYTES);
        }
        reverse_search(start_ptr, end_ptr, ptr, confirm)
    }
}
/// Like `memrchr`, but searches for two bytes instead of one.
Like `memrchr`, but searches for two bytes instead of one.
Like ` memrchr ` but searches for two bytes instead of one .
pub fn memrchr2(n1: u8, n2: u8, haystack: &[u8]) -> Option<usize> {
    let vn1 = repeat_byte(n1);
    let vn2 = repeat_byte(n2);
    let confirm = |byte| byte == n1 || byte == n2;
    let align = USIZE_BYTES - 1;
    let start_ptr = haystack.as_ptr();
    unsafe {
        let end_ptr = start_ptr.add(haystack.len());
        let mut ptr = end_ptr;
        if haystack.len() < USIZE_BYTES {
            return reverse_search(start_ptr, end_ptr, ptr, confirm);
        }
        let chunk = (ptr.sub(USIZE_BYTES) as *const usize).read_unaligned();
        let eq1 = contains_zero_byte(chunk ^ vn1);
        let eq2 = contains_zero_byte(chunk ^ vn2);
        if eq1 || eq2 {
            return reverse_search(start_ptr, end_ptr, ptr, confirm);
        }
        ptr = (end_ptr as usize & !align) as *const u8;
        debug_assert!(start_ptr <= ptr && ptr <= end_ptr);
        while ptr >= start_ptr.add(USIZE_BYTES) {
            debug_assert_eq!(0, (ptr as usize) % USIZE_BYTES);
            let chunk = *(ptr.sub(USIZE_BYTES) as *const usize);
            let eq1 = contains_zero_byte(chunk ^ vn1);
            let eq2 = contains_zero_byte(chunk ^ vn2);
            if eq1 || eq2 {
                break;
            }
            ptr = ptr.sub(USIZE_BYTES);
        }
        reverse_search(start_ptr, end_ptr, ptr, confirm)
    }
}
pub fn memrchr2 ( n1 : u8 , n2 : u8 , haystack : & [ u8 ] ) -> Option < usize > { let vn1 = repeat_byte ( n1 ) ; let vn2 = repeat_byte ( n2 ) ; let confirm = | byte | byte == n1 || byte == n2 ; let align = USIZE_BYTES - 1 ; let start_ptr = haystack . as_ptr ( ) ; unsafe { let end_ptr = start_ptr . add ( haystack . len ( ) ) ; let mut ptr = end_ptr ; if haystack . len ( ) < USIZE_BYTES { return reverse_search ( start_ptr , end_ptr , ptr , confirm ) ; } let chunk = ( ptr . sub ( USIZE_BYTES ) as * const usize ) . read_unaligned ( ) ; let eq1 = contains_zero_byte ( chunk ^ vn1 ) ; let eq2 = contains_zero_byte ( chunk ^ vn2 ) ; if eq1 || eq2 { return reverse_search ( start_ptr , end_ptr , ptr , confirm ) ; } ptr = ( end_ptr as usize & ! align ) as * const u8 ; debug_assert ! ( start_ptr ptr ptr end_ptr ) ; while ptr >= start_ptr . add ( USIZE_BYTES ) { debug_assert_eq ! ( 0 ( ptr as usize ) USIZE_BYTES ) ; let chunk = * ( ptr . sub ( USIZE_BYTES ) as * const usize ) ; let eq1 = contains_zero_byte ( chunk ^ vn1 ) ; let eq2 = contains_zero_byte ( chunk ^ vn2 ) ; if eq1 || eq2 { break ; } ptr = ptr . sub ( USIZE_BYTES ) ; } reverse_search ( start_ptr , end_ptr , ptr , confirm ) } }
Like `memrchr`, but searches for two bytes instead of one.
Like ` memrchr ` but searches for two bytes instead of one .
n1
u8
n2
u8
haystack
&[u8]
n1
u8
n2
u8
haystack
&[u8]