@@ -382,7 +382,7 @@ impl<N: Needle> Avx2Searcher<N> {
382
382
/// up to a length of thirteen it uses specialized versions of `Avx2Searcher`,
383
383
/// finally falling back to the generic version of `Avx2Searcher` for longer
384
384
/// needles.
385
- pub enum DynamicAvx2Searcher {
385
+ pub enum DynamicAvx2Searcher < N : Needle > {
386
386
/// Specialization for needles with length 0.
387
387
N0 ,
388
388
/// Specialization for needles with length 1.
@@ -412,17 +412,17 @@ pub enum DynamicAvx2Searcher {
412
412
/// Specialization for needles with length 13.
413
413
N13 ( Avx2Searcher < [ u8 ; 13 ] > ) ,
414
414
/// Fallback implementation for needles of any size.
415
- N ( Avx2Searcher < Box < [ u8 ] > > ) ,
415
+ N ( Avx2Searcher < N > ) ,
416
416
}
417
417
418
- impl DynamicAvx2Searcher {
418
+ impl < N : Needle > DynamicAvx2Searcher < N > {
419
419
/// Creates a new searcher for `needle`. By default, `position` is set to
420
420
/// the last character in the needle.
421
421
#[ target_feature( enable = "avx2" ) ]
422
- pub unsafe fn new ( needle : Box < [ u8 ] > ) -> Self {
422
+ pub unsafe fn new ( needle : N ) -> Self {
423
423
// Wrapping prevents panicking on unsigned integer underflow when
424
424
// `needle` is empty.
425
- let position = needle. len ( ) . wrapping_sub ( 1 ) ;
425
+ let position = needle. as_bytes ( ) . len ( ) . wrapping_sub ( 1 ) ;
426
426
Self :: with_position ( needle, position)
427
427
}
428
428
@@ -433,8 +433,8 @@ impl DynamicAvx2Searcher {
433
433
/// When `needle` is not empty, panics if `position` is not a valid index
434
434
/// for `needle`.
435
435
#[ 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 ( ) {
438
438
[ ] => Self :: N0 ,
439
439
[ c0] => {
440
440
// Check that `position` is set correctly for consistency.
@@ -722,6 +722,9 @@ mod tests {
722
722
fn size_of_dynamic_avx2_searcher ( ) {
723
723
use std:: mem:: size_of;
724
724
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 ) ;
726
729
}
727
730
}
0 commit comments