mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-06 12:04:36 +00:00
Shrink MatcherPosRepetition
.
Currently it copies a `KleeneOp` and a `Token` out of a `SequenceRepetition`. It's better to store a reference to the `SequenceRepetition`, which is now possible due to #95159 having changed the lifetimes.
This commit is contained in:
parent
cad5f1e774
commit
fdec26ddad
@ -160,7 +160,7 @@ struct MatcherPos<'tt> {
|
|||||||
|
|
||||||
// This type is used a lot. Make sure it doesn't unintentionally get bigger.
|
// This type is used a lot. Make sure it doesn't unintentionally get bigger.
|
||||||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
||||||
rustc_data_structures::static_assert_size!(MatcherPos<'_>, 136);
|
rustc_data_structures::static_assert_size!(MatcherPos<'_>, 112);
|
||||||
|
|
||||||
impl<'tt> MatcherPos<'tt> {
|
impl<'tt> MatcherPos<'tt> {
|
||||||
/// `len` `Vec`s (initially shared and empty) that will store matches of metavars.
|
/// `len` `Vec`s (initially shared and empty) that will store matches of metavars.
|
||||||
@ -209,11 +209,7 @@ impl<'tt> MatcherPos<'tt> {
|
|||||||
match_lo: up.match_cur,
|
match_lo: up.match_cur,
|
||||||
match_cur: up.match_cur,
|
match_cur: up.match_cur,
|
||||||
match_hi: up.match_cur + seq.num_captures,
|
match_hi: up.match_cur + seq.num_captures,
|
||||||
repetition: Some(MatcherPosRepetition {
|
repetition: Some(MatcherPosRepetition { up, seq }),
|
||||||
up,
|
|
||||||
sep: seq.separator.clone(),
|
|
||||||
seq_op: seq.kleene.op,
|
|
||||||
}),
|
|
||||||
stack: smallvec![],
|
stack: smallvec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -227,15 +223,12 @@ impl<'tt> MatcherPos<'tt> {
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct MatcherPosRepetition<'tt> {
|
struct MatcherPosRepetition<'tt> {
|
||||||
/// The KleeneOp of this sequence.
|
|
||||||
seq_op: mbe::KleeneOp,
|
|
||||||
|
|
||||||
/// The separator.
|
|
||||||
sep: Option<Token>,
|
|
||||||
|
|
||||||
/// The "parent" matcher position. That is, the matcher position just before we enter the
|
/// The "parent" matcher position. That is, the matcher position just before we enter the
|
||||||
/// sequence.
|
/// sequence.
|
||||||
up: Box<MatcherPos<'tt>>,
|
up: Box<MatcherPos<'tt>>,
|
||||||
|
|
||||||
|
/// The sequence itself.
|
||||||
|
seq: &'tt SequenceRepetition,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum EofItems<'tt> {
|
enum EofItems<'tt> {
|
||||||
@ -559,14 +552,19 @@ impl<'tt> TtParser<'tt> {
|
|||||||
self.cur_items.push(new_pos);
|
self.cur_items.push(new_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
if idx == len && repetition.sep.is_some() {
|
if idx == len && repetition.seq.separator.is_some() {
|
||||||
if repetition.sep.as_ref().map_or(false, |sep| token_name_eq(token, sep)) {
|
if repetition
|
||||||
|
.seq
|
||||||
|
.separator
|
||||||
|
.as_ref()
|
||||||
|
.map_or(false, |sep| token_name_eq(token, sep))
|
||||||
|
{
|
||||||
// The matcher has a separator, and it matches the current token. We can
|
// The matcher has a separator, and it matches the current token. We can
|
||||||
// advance past the separator token.
|
// advance past the separator token.
|
||||||
item.idx += 1;
|
item.idx += 1;
|
||||||
self.next_items.push(item);
|
self.next_items.push(item);
|
||||||
}
|
}
|
||||||
} else if repetition.seq_op != mbe::KleeneOp::ZeroOrOne {
|
} else if repetition.seq.kleene.op != mbe::KleeneOp::ZeroOrOne {
|
||||||
// We don't need a separator. Move the "dot" back to the beginning of the
|
// We don't need a separator. Move the "dot" back to the beginning of the
|
||||||
// matcher and try to match again UNLESS we are only allowed to have _one_
|
// matcher and try to match again UNLESS we are only allowed to have _one_
|
||||||
// repetition.
|
// repetition.
|
||||||
|
Loading…
Reference in New Issue
Block a user