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

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

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

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

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