@@ -11,9 +11,9 @@ use rustc_expand::base::{self, *};
11
11
use rustc_parse_format as parse;
12
12
use rustc_span:: symbol:: { sym, Ident , Symbol } ;
13
13
use rustc_span:: { MultiSpan , Span } ;
14
+ use smallvec:: SmallVec ;
14
15
15
16
use std:: borrow:: Cow ;
16
- use std:: cmp:: Ordering ;
17
17
use std:: collections:: hash_map:: Entry ;
18
18
19
19
#[ derive( PartialEq ) ]
@@ -760,21 +760,23 @@ impl<'a, 'b> Context<'a, 'b> {
760
760
// "{1} {0}"), or may have multiple entries referring to the same
761
761
// element of original_args ("{0} {0}").
762
762
//
763
- // The following Iterator<Item = (usize, &ArgumentType)> has one item
764
- // per element of our output slice, identifying the index of which
765
- // element of original_args it's passing, and that argument's type.
766
- let fmt_arg_index_and_ty = self
767
- . arg_unique_types
768
- . iter ( )
769
- . enumerate ( )
770
- . flat_map ( |( i, unique_types) | unique_types. iter ( ) . map ( move |ty| ( i, ty) ) )
771
- . chain ( self . count_args . iter ( ) . map ( |i| ( * i, & Count ) ) ) ;
763
+ // The following vector has one item per element of our output slice,
764
+ // identifying the index of which element of original_args it's passing,
765
+ // and that argument's type.
766
+ let mut fmt_arg_index_and_ty = SmallVec :: < [ ( usize , & ArgumentType ) ; 8 ] > :: new ( ) ;
767
+ for ( i, unique_types) in self . arg_unique_types . iter ( ) . enumerate ( ) {
768
+ fmt_arg_index_and_ty. extend ( unique_types. iter ( ) . map ( |ty| ( i, ty) ) ) ;
769
+ }
770
+ fmt_arg_index_and_ty. extend ( self . count_args . iter ( ) . map ( |& i| ( i, & Count ) ) ) ;
772
771
773
772
// Figure out whether there are permuted or repeated elements. If not,
774
773
// we can generate simpler code.
775
- let nicely_ordered = fmt_arg_index_and_ty
776
- . clone ( )
777
- . is_sorted_by ( |( i, _) , ( j, _) | ( i < j) . then_some ( Ordering :: Less ) ) ;
774
+ //
775
+ // The sequence has no indices out of order or repeated if: for every
776
+ // adjacent pair of elements, the first one's index is less than the
777
+ // second one's index.
778
+ let nicely_ordered =
779
+ fmt_arg_index_and_ty. array_windows ( ) . all ( |[ ( i, _i_ty) , ( j, _j_ty) ] | i < j) ;
778
780
779
781
// We want to emit:
780
782
//
0 commit comments