Skip to content

Commit fdec26d

Browse files
committed
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 rust-lang#95159 having changed the lifetimes.
1 parent cad5f1e commit fdec26d

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

compiler/rustc_expand/src/mbe/macro_parser.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ struct MatcherPos<'tt> {
160160

161161
// This type is used a lot. Make sure it doesn't unintentionally get bigger.
162162
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
163-
rustc_data_structures::static_assert_size!(MatcherPos<'_>, 136);
163+
rustc_data_structures::static_assert_size!(MatcherPos<'_>, 112);
164164

165165
impl<'tt> MatcherPos<'tt> {
166166
/// `len` `Vec`s (initially shared and empty) that will store matches of metavars.
@@ -209,11 +209,7 @@ impl<'tt> MatcherPos<'tt> {
209209
match_lo: up.match_cur,
210210
match_cur: up.match_cur,
211211
match_hi: up.match_cur + seq.num_captures,
212-
repetition: Some(MatcherPosRepetition {
213-
up,
214-
sep: seq.separator.clone(),
215-
seq_op: seq.kleene.op,
216-
}),
212+
repetition: Some(MatcherPosRepetition { up, seq }),
217213
stack: smallvec![],
218214
}
219215
}
@@ -227,15 +223,12 @@ impl<'tt> MatcherPos<'tt> {
227223

228224
#[derive(Clone)]
229225
struct MatcherPosRepetition<'tt> {
230-
/// The KleeneOp of this sequence.
231-
seq_op: mbe::KleeneOp,
232-
233-
/// The separator.
234-
sep: Option<Token>,
235-
236226
/// The "parent" matcher position. That is, the matcher position just before we enter the
237227
/// sequence.
238228
up: Box<MatcherPos<'tt>>,
229+
230+
/// The sequence itself.
231+
seq: &'tt SequenceRepetition,
239232
}
240233

241234
enum EofItems<'tt> {
@@ -559,14 +552,19 @@ impl<'tt> TtParser<'tt> {
559552
self.cur_items.push(new_pos);
560553
}
561554

562-
if idx == len && repetition.sep.is_some() {
563-
if repetition.sep.as_ref().map_or(false, |sep| token_name_eq(token, sep)) {
555+
if idx == len && repetition.seq.separator.is_some() {
556+
if repetition
557+
.seq
558+
.separator
559+
.as_ref()
560+
.map_or(false, |sep| token_name_eq(token, sep))
561+
{
564562
// The matcher has a separator, and it matches the current token. We can
565563
// advance past the separator token.
566564
item.idx += 1;
567565
self.next_items.push(item);
568566
}
569-
} else if repetition.seq_op != mbe::KleeneOp::ZeroOrOne {
567+
} else if repetition.seq.kleene.op != mbe::KleeneOp::ZeroOrOne {
570568
// We don't need a separator. Move the "dot" back to the beginning of the
571569
// matcher and try to match again UNLESS we are only allowed to have _one_
572570
// repetition.

0 commit comments

Comments
 (0)