@@ -143,6 +143,8 @@ struct MatcherTtFrame<'a> {
143
143
idx : usize ,
144
144
}
145
145
146
+ type NamedMatchVec = SmallVec < [ NamedMatch ; 4 ] > ;
147
+
146
148
/// Represents a single "position" (aka "matcher position", aka "item"), as described in the module
147
149
/// documentation.
148
150
#[ derive( Clone ) ]
@@ -168,7 +170,7 @@ struct MatcherPos<'a> {
168
170
/// all bound matches from the submatcher into the shared top-level `matches` vector. If `sep`
169
171
/// and `up` are `Some`, then `matches` is _not_ the shared top-level list. Instead, if one
170
172
/// wants the shared `matches`, one should use `up.matches`.
171
- matches : Box < [ Rc < Vec < NamedMatch > > ] > ,
173
+ matches : Box < [ Rc < NamedMatchVec > ] > ,
172
174
/// The position in `matches` corresponding to the first metavar in this matcher's sequence of
173
175
/// token trees. In other words, the first metavar in the first token of `top_elts` corresponds
174
176
/// to `matches[match_lo]`.
@@ -279,11 +281,11 @@ pub fn count_names(ms: &[TokenTree]) -> usize {
279
281
}
280
282
281
283
/// `len` `Vec`s (initially shared and empty) that will store matches of metavars.
282
- fn create_matches ( len : usize ) -> Box < [ Rc < Vec < NamedMatch > > ] > {
284
+ fn create_matches ( len : usize ) -> Box < [ Rc < NamedMatchVec > ] > {
283
285
if len == 0 {
284
286
vec ! [ ]
285
287
} else {
286
- let empty_matches = Rc :: new ( Vec :: new ( ) ) ;
288
+ let empty_matches = Rc :: new ( SmallVec :: new ( ) ) ;
287
289
vec ! [ empty_matches. clone( ) ; len]
288
290
} . into_boxed_slice ( )
289
291
}
@@ -337,7 +339,7 @@ fn initial_matcher_pos(ms: &[TokenTree], open: Span) -> MatcherPos {
337
339
/// token tree it was derived from.
338
340
#[ derive( Debug , Clone ) ]
339
341
pub enum NamedMatch {
340
- MatchedSeq ( Rc < Vec < NamedMatch > > , DelimSpan ) ,
342
+ MatchedSeq ( Rc < NamedMatchVec > , DelimSpan ) ,
341
343
MatchedNonterminal ( Rc < Nonterminal > ) ,
342
344
}
343
345
@@ -545,7 +547,7 @@ fn inner_parse_loop<'a>(
545
547
new_item. match_cur += seq. num_captures ;
546
548
new_item. idx += 1 ;
547
549
for idx in item. match_cur ..item. match_cur + seq. num_captures {
548
- new_item. push_match ( idx, MatchedSeq ( Rc :: new ( vec ! [ ] ) , sp) ) ;
550
+ new_item. push_match ( idx, MatchedSeq ( Rc :: new ( smallvec ! [ ] ) , sp) ) ;
549
551
}
550
552
cur_items. push ( new_item) ;
551
553
}
0 commit comments