@@ -967,32 +967,37 @@ macro_rules! impl_choice_for_tuple {
967967 // Note that this tends to pessimise behaviour for EmptyErr (which presumably optimises to an jump table already),
968968 // so we detect this case and skip this optimisation using size_of.
969969 #[ cfg( feature = "nightly" ) ]
970- if core:: mem:: size_of:: <E :: Error >( ) > 0 && $Head:: Jump :: SUPPORTS $( && $X:: Jump :: SUPPORTS ) * {
971- if let Some ( next) = inp. peek_maybe( ) . as_deref( ) {
972- match next {
973- // The hope is that the optimiser folds this arm condition into the match in such a way that we end up with a jump table
974- _ if $Head. will_match( & next) => return $Head. go:: <M >( inp) ,
975- $(
976- _ if $X. will_match( & next) => return $X. go:: <M >( inp) ,
977- ) *
978- _ => return Err ( ( ) ) ,
970+ if core:: mem:: size_of:: <E :: Error >( ) > 0
971+ && $Head:: Jump :: SUPPORTS $( && $X:: Jump :: SUPPORTS ) *
972+ && ( 1 $( + $X:: Jump :: SUPPORTS as u64 ) * ) > 1
973+ {
974+ return if let Some ( next) = inp. peek_maybe_inner( ) . as_ref( ) . map( Borrow :: borrow) {
975+ if $Head. will_match( & next) {
976+ $Head. go:: <M >( inp)
977+ } $( else if $X. will_match( & next) {
978+ $X. go:: <M >( inp)
979+ } ) * else {
980+ Err ( ( ) )
979981 }
980- }
981- }
982-
983- match $Head. go:: <M >( inp) {
984- Ok ( out) => return Ok ( out) ,
985- Err ( ( ) ) => inp. rewind( before. clone( ) ) ,
986- }
987-
988- $(
989- match $X. go:: <M >( inp) {
982+ } else {
983+ Err ( ( ) )
984+ } ;
985+ } else {
986+ match $Head. go:: <M >( inp) {
990987 Ok ( out) => return Ok ( out) ,
991- Err ( ( ) ) => inp . rewind ( before . clone ( ) ) ,
988+ Err ( ( ) ) => { } ,
992989 }
993- ) *
994990
995- Err ( ( ) )
991+ $(
992+ inp. rewind( before. clone( ) ) ;
993+ match $X. go:: <M >( inp) {
994+ Ok ( out) => return Ok ( out) ,
995+ Err ( ( ) ) => { } ,
996+ }
997+ ) *
998+
999+ Err ( ( ) )
1000+ }
9961001 }
9971002
9981003 go_extra!( O ) ;
0 commit comments