Make MatcherPos
not derive Clone
.
It's only used in one place, and there we clone and then make a bunch of modifications. It's clearer if we duplicate more explicitly, and there's a symmetry now between `sequence()` and `empty_sequence()`.
This commit is contained in:
parent
f68a0449ed
commit
c6fedd4f10
1 changed files with 24 additions and 8 deletions
|
@ -132,7 +132,6 @@ struct Parent<'tt> {
|
||||||
/// <--------------> first submatcher; three tts, zero metavars
|
/// <--------------> first submatcher; three tts, zero metavars
|
||||||
/// <--------------------------> top-level matcher; two tts, one metavar
|
/// <--------------------------> top-level matcher; two tts, one metavar
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Clone)]
|
|
||||||
struct MatcherPos<'tt> {
|
struct MatcherPos<'tt> {
|
||||||
/// The tokens that make up the current matcher. When we are within a `Sequence` or `Delimited`
|
/// The tokens that make up the current matcher. When we are within a `Sequence` or `Delimited`
|
||||||
/// submatcher, this is just the contents of that submatcher.
|
/// submatcher, this is just the contents of that submatcher.
|
||||||
|
@ -177,6 +176,25 @@ impl<'tt> MatcherPos<'tt> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn empty_sequence(
|
||||||
|
parent_mp: &MatcherPos<'tt>,
|
||||||
|
seq: &'tt SequenceRepetition,
|
||||||
|
empty_matches: Lrc<NamedMatchVec>,
|
||||||
|
) -> Self {
|
||||||
|
let mut mp = MatcherPos {
|
||||||
|
tts: parent_mp.tts,
|
||||||
|
idx: parent_mp.idx + 1,
|
||||||
|
matches: parent_mp.matches.clone(), // a cheap clone
|
||||||
|
seq_depth: parent_mp.seq_depth,
|
||||||
|
match_cur: parent_mp.match_cur + seq.num_captures,
|
||||||
|
kind: parent_mp.kind.clone(), // an expensive clone
|
||||||
|
};
|
||||||
|
for idx in parent_mp.match_cur..parent_mp.match_cur + seq.num_captures {
|
||||||
|
mp.push_match(idx, MatchedSeq(empty_matches.clone()));
|
||||||
|
}
|
||||||
|
mp
|
||||||
|
}
|
||||||
|
|
||||||
fn sequence(
|
fn sequence(
|
||||||
parent_mp: Box<MatcherPos<'tt>>,
|
parent_mp: Box<MatcherPos<'tt>>,
|
||||||
seq: &'tt SequenceRepetition,
|
seq: &'tt SequenceRepetition,
|
||||||
|
@ -468,13 +486,11 @@ impl<'tt> TtParser<'tt> {
|
||||||
let op = seq.kleene.op;
|
let op = seq.kleene.op;
|
||||||
if op == mbe::KleeneOp::ZeroOrMore || op == mbe::KleeneOp::ZeroOrOne {
|
if op == mbe::KleeneOp::ZeroOrMore || op == mbe::KleeneOp::ZeroOrOne {
|
||||||
// Allow for the possibility of zero matches of this sequence.
|
// Allow for the possibility of zero matches of this sequence.
|
||||||
let mut new_mp = mp.clone();
|
self.cur_mps.push(box MatcherPos::empty_sequence(
|
||||||
new_mp.match_cur += seq.num_captures;
|
&*mp,
|
||||||
new_mp.idx += 1;
|
&seq,
|
||||||
for idx in mp.match_cur..mp.match_cur + seq.num_captures {
|
self.empty_matches.clone(),
|
||||||
new_mp.push_match(idx, MatchedSeq(self.empty_matches.clone()));
|
));
|
||||||
}
|
|
||||||
self.cur_mps.push(new_mp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow for the possibility of one or more matches of this sequence.
|
// Allow for the possibility of one or more matches of this sequence.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue