@@ -11,9 +11,9 @@ use rustc_expand::base::{self, *};
1111use rustc_parse_format as parse;
1212use rustc_span:: symbol:: { sym, Ident , Symbol } ;
1313use rustc_span:: { MultiSpan , Span } ;
14+ use smallvec:: SmallVec ;
1415
1516use std:: borrow:: Cow ;
16- use std:: cmp:: Ordering ;
1717use std:: collections:: hash_map:: Entry ;
1818
1919#[ derive( PartialEq ) ]
@@ -760,21 +760,23 @@ impl<'a, 'b> Context<'a, 'b> {
760760 // "{1} {0}"), or may have multiple entries referring to the same
761761 // element of original_args ("{0} {0}").
762762 //
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 ) ) ) ;
772771
773772 // Figure out whether there are permuted or repeated elements. If not,
774773 // 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) ;
778780
779781 // We want to emit:
780782 //
0 commit comments