11#![ allow( clippy:: missing_safety_doc) ]
22
33use crate :: { bits, memcmp, MemchrSearcher , Needle } ;
4+ use seq_macro:: seq;
45#[ cfg( target_arch = "x86" ) ]
56use std:: arch:: x86:: * ;
67#[ cfg( target_arch = "x86_64" ) ]
@@ -415,6 +416,12 @@ pub enum DynamicAvx2Searcher<N: Needle> {
415416 N ( Avx2Searcher < N > ) ,
416417}
417418
419+ macro_rules! array {
420+ ( $c: ident, $S: literal) => [ seq!( N in 0 ..$S {
421+ [ #( $c#N , ) * ]
422+ } ) ] ;
423+ }
424+
418425impl < N : Needle > DynamicAvx2Searcher < N > {
419426 /// Creates a new searcher for `needle`. By default, `position` is set to
420427 /// the last character in the needle.
@@ -441,50 +448,18 @@ impl<N: Needle> DynamicAvx2Searcher<N> {
441448 assert_eq ! ( position, 0 ) ;
442449 Self :: N1 ( MemchrSearcher :: new ( c0) )
443450 }
444- [ c0, c1] => Self :: N2 ( Avx2Searcher :: with_position ( [ c0, c1] , position) ) ,
445- [ c0, c1, c2] => Self :: N3 ( Avx2Searcher :: with_position ( [ c0, c1, c2] , position) ) ,
446- [ c0, c1, c2, c3] => Self :: N4 ( Avx2Searcher :: with_position ( [ c0, c1, c2, c3] , position) ) ,
447- [ c0, c1, c2, c3, c4] => {
448- Self :: N5 ( Avx2Searcher :: with_position ( [ c0, c1, c2, c3, c4] , position) )
449- }
450- [ c0, c1, c2, c3, c4, c5] => Self :: N6 ( Avx2Searcher :: with_position (
451- [ c0, c1, c2, c3, c4, c5] ,
452- position,
453- ) ) ,
454- [ c0, c1, c2, c3, c4, c5, c6] => Self :: N7 ( Avx2Searcher :: with_position (
455- [ c0, c1, c2, c3, c4, c5, c6] ,
456- position,
457- ) ) ,
458- [ c0, c1, c2, c3, c4, c5, c6, c7] => Self :: N8 ( Avx2Searcher :: with_position (
459- [ c0, c1, c2, c3, c4, c5, c6, c7] ,
460- position,
461- ) ) ,
462- [ c0, c1, c2, c3, c4, c5, c6, c7, c8] => Self :: N9 ( Avx2Searcher :: with_position (
463- [ c0, c1, c2, c3, c4, c5, c6, c7, c8] ,
464- position,
465- ) ) ,
466- [ c0, c1, c2, c3, c4, c5, c6, c7, c8, c9] => Self :: N10 ( Avx2Searcher :: with_position (
467- [ c0, c1, c2, c3, c4, c5, c6, c7, c8, c9] ,
468- position,
469- ) ) ,
470- [ c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10] => {
471- Self :: N11 ( Avx2Searcher :: with_position (
472- [ c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10] ,
473- position,
474- ) )
475- }
476- [ c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11] => {
477- Self :: N12 ( Avx2Searcher :: with_position (
478- [ c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11] ,
479- position,
480- ) )
481- }
482- [ c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12] => {
483- Self :: N13 ( Avx2Searcher :: with_position (
484- [ c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12] ,
485- position,
486- ) )
487- }
451+ array ! ( c, 2 ) => Self :: N2 ( Avx2Searcher :: with_position ( array ! ( c, 2 ) , position) ) ,
452+ array ! ( c, 3 ) => Self :: N3 ( Avx2Searcher :: with_position ( array ! ( c, 3 ) , position) ) ,
453+ array ! ( c, 4 ) => Self :: N4 ( Avx2Searcher :: with_position ( array ! ( c, 4 ) , position) ) ,
454+ array ! ( c, 5 ) => Self :: N5 ( Avx2Searcher :: with_position ( array ! ( c, 5 ) , position) ) ,
455+ array ! ( c, 6 ) => Self :: N6 ( Avx2Searcher :: with_position ( array ! ( c, 6 ) , position) ) ,
456+ array ! ( c, 7 ) => Self :: N7 ( Avx2Searcher :: with_position ( array ! ( c, 7 ) , position) ) ,
457+ array ! ( c, 8 ) => Self :: N8 ( Avx2Searcher :: with_position ( array ! ( c, 8 ) , position) ) ,
458+ array ! ( c, 9 ) => Self :: N9 ( Avx2Searcher :: with_position ( array ! ( c, 9 ) , position) ) ,
459+ array ! ( c, 10 ) => Self :: N10 ( Avx2Searcher :: with_position ( array ! ( c, 10 ) , position) ) ,
460+ array ! ( c, 11 ) => Self :: N11 ( Avx2Searcher :: with_position ( array ! ( c, 11 ) , position) ) ,
461+ array ! ( c, 12 ) => Self :: N12 ( Avx2Searcher :: with_position ( array ! ( c, 12 ) , position) ) ,
462+ array ! ( c, 13 ) => Self :: N13 ( Avx2Searcher :: with_position ( array ! ( c, 13 ) , position) ) ,
488463 _ => Self :: N ( Avx2Searcher :: with_position ( needle, position) ) ,
489464 }
490465 }
0 commit comments