@@ -132,7 +132,6 @@ struct Parent<'tt> {
132
132
/// <--------------> first submatcher; three tts, zero metavars
133
133
/// <--------------------------> top-level matcher; two tts, one metavar
134
134
/// ```
135
- #[ derive( Clone ) ]
136
135
struct MatcherPos < ' tt > {
137
136
/// The tokens that make up the current matcher. When we are within a `Sequence` or `Delimited`
138
137
/// submatcher, this is just the contents of that submatcher.
@@ -177,6 +176,25 @@ impl<'tt> MatcherPos<'tt> {
177
176
}
178
177
}
179
178
179
+ fn empty_sequence (
180
+ parent_mp : & MatcherPos < ' tt > ,
181
+ seq : & ' tt SequenceRepetition ,
182
+ empty_matches : Lrc < NamedMatchVec > ,
183
+ ) -> Self {
184
+ let mut mp = MatcherPos {
185
+ tts : parent_mp. tts ,
186
+ idx : parent_mp. idx + 1 ,
187
+ matches : parent_mp. matches . clone ( ) , // a cheap clone
188
+ seq_depth : parent_mp. seq_depth ,
189
+ match_cur : parent_mp. match_cur + seq. num_captures ,
190
+ kind : parent_mp. kind . clone ( ) , // an expensive clone
191
+ } ;
192
+ for idx in parent_mp. match_cur ..parent_mp. match_cur + seq. num_captures {
193
+ mp. push_match ( idx, MatchedSeq ( empty_matches. clone ( ) ) ) ;
194
+ }
195
+ mp
196
+ }
197
+
180
198
fn sequence (
181
199
parent_mp : Box < MatcherPos < ' tt > > ,
182
200
seq : & ' tt SequenceRepetition ,
@@ -468,13 +486,11 @@ impl<'tt> TtParser<'tt> {
468
486
let op = seq. kleene . op ;
469
487
if op == mbe:: KleeneOp :: ZeroOrMore || op == mbe:: KleeneOp :: ZeroOrOne {
470
488
// Allow for the possibility of zero matches of this sequence.
471
- let mut new_mp = mp. clone ( ) ;
472
- new_mp. match_cur += seq. num_captures ;
473
- new_mp. idx += 1 ;
474
- for idx in mp. match_cur ..mp. match_cur + seq. num_captures {
475
- new_mp. push_match ( idx, MatchedSeq ( self . empty_matches . clone ( ) ) ) ;
476
- }
477
- self . cur_mps . push ( new_mp) ;
489
+ self . cur_mps . push ( box MatcherPos :: empty_sequence (
490
+ & * mp,
491
+ & seq,
492
+ self . empty_matches . clone ( ) ,
493
+ ) ) ;
478
494
}
479
495
480
496
// Allow for the possibility of one or more matches of this sequence.
0 commit comments