@@ -382,7 +382,7 @@ impl<N: Needle> Avx2Searcher<N> {
382382/// up to a length of thirteen it uses specialized versions of `Avx2Searcher`,
383383/// finally falling back to the generic version of `Avx2Searcher` for longer
384384/// needles.
385- pub enum DynamicAvx2Searcher {
385+ pub enum DynamicAvx2Searcher < N : Needle > {
386386 /// Specialization for needles with length 0.
387387 N0 ,
388388 /// Specialization for needles with length 1.
@@ -412,17 +412,17 @@ pub enum DynamicAvx2Searcher {
412412 /// Specialization for needles with length 13.
413413 N13 ( Avx2Searcher < [ u8 ; 13 ] > ) ,
414414 /// Fallback implementation for needles of any size.
415- N ( Avx2Searcher < Box < [ u8 ] > > ) ,
415+ N ( Avx2Searcher < N > ) ,
416416}
417417
418- impl DynamicAvx2Searcher {
418+ impl < N : Needle > DynamicAvx2Searcher < N > {
419419 /// Creates a new searcher for `needle`. By default, `position` is set to
420420 /// the last character in the needle.
421421 #[ target_feature( enable = "avx2" ) ]
422- pub unsafe fn new ( needle : Box < [ u8 ] > ) -> Self {
422+ pub unsafe fn new ( needle : N ) -> Self {
423423 // Wrapping prevents panicking on unsigned integer underflow when
424424 // `needle` is empty.
425- let position = needle. len ( ) . wrapping_sub ( 1 ) ;
425+ let position = needle. as_bytes ( ) . len ( ) . wrapping_sub ( 1 ) ;
426426 Self :: with_position ( needle, position)
427427 }
428428
@@ -433,8 +433,8 @@ impl DynamicAvx2Searcher {
433433 /// When `needle` is not empty, panics if `position` is not a valid index
434434 /// for `needle`.
435435 #[ target_feature( enable = "avx2" ) ]
436- pub unsafe fn with_position ( needle : Box < [ u8 ] > , position : usize ) -> Self {
437- match * needle {
436+ pub unsafe fn with_position ( needle : N , position : usize ) -> Self {
437+ match * needle. as_bytes ( ) {
438438 [ ] => Self :: N0 ,
439439 [ c0] => {
440440 // Check that `position` is set correctly for consistency.
@@ -722,6 +722,9 @@ mod tests {
722722 fn size_of_dynamic_avx2_searcher ( ) {
723723 use std:: mem:: size_of;
724724
725- assert_eq ! ( size_of:: <DynamicAvx2Searcher >( ) , 160 ) ;
725+ assert_eq ! ( size_of:: <DynamicAvx2Searcher :: <& [ u8 ] >>( ) , 160 ) ;
726+ assert_eq ! ( size_of:: <DynamicAvx2Searcher :: <[ u8 ; 0 ] >>( ) , 160 ) ;
727+ assert_eq ! ( size_of:: <DynamicAvx2Searcher :: <[ u8 ; 16 ] >>( ) , 160 ) ;
728+ assert_eq ! ( size_of:: <DynamicAvx2Searcher :: <Box <[ u8 ] >>>( ) , 160 ) ;
726729 }
727730}
0 commit comments