Skip to content

Commit ffd2142

Browse files
committed
Remove the DelimSpan from NamedMatch::MatchedSeq.
Because it's unused. This then allows the removal of `MatcherPos::sp_open`. It's a tiny perf win, reducing instruction counts by 0.1% - 0.2% on a few benchmarks.
1 parent 7dbfb0a commit ffd2142

File tree

3 files changed

+11
-20
lines changed

3 files changed

+11
-20
lines changed

src/libsyntax_expand/mbe/macro_parser.rs

+7-16
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ use syntax::print::pprust;
8383
use syntax::sess::ParseSess;
8484
use syntax::symbol::{kw, sym, Symbol};
8585
use syntax::token::{self, DocComment, Nonterminal, Token};
86-
use syntax::tokenstream::{DelimSpan, TokenStream};
86+
use syntax::tokenstream::TokenStream;
8787

8888
use errors::{PResult, FatalError};
8989
use smallvec::{smallvec, SmallVec};
@@ -164,11 +164,6 @@ struct MatcherPos<'root, 'tt> {
164164
/// The position of the "dot" in this matcher
165165
idx: usize,
166166

167-
/// The first span of source that the beginning of this matcher corresponds to. In other
168-
/// words, the token in the source whose span is `sp_open` is matched against the first token of
169-
/// the matcher.
170-
sp_open: Span,
171-
172167
/// For each named metavar in the matcher, we keep track of token trees matched against the
173168
/// metavar by the black box parser. In particular, there may be more than one match per
174169
/// metavar if we are in a repetition (each repetition matches each of the variables).
@@ -307,17 +302,15 @@ fn create_matches(len: usize) -> Box<[Lrc<NamedMatchVec>]> {
307302
}
308303

309304
/// Generates the top-level matcher position in which the "dot" is before the first token of the
310-
/// matcher `ms` and we are going to start matching at the span `open` in the source.
311-
fn initial_matcher_pos<'root, 'tt>(ms: &'tt [TokenTree], open: Span) -> MatcherPos<'root, 'tt> {
305+
/// matcher `ms`.
306+
fn initial_matcher_pos<'root, 'tt>(ms: &'tt [TokenTree]) -> MatcherPos<'root, 'tt> {
312307
let match_idx_hi = count_names(ms);
313308
let matches = create_matches(match_idx_hi);
314309
MatcherPos {
315310
// Start with the top level matcher given to us
316311
top_elts: TtSeq(ms), // "elts" is an abbr. for "elements"
317312
// The "dot" is before the first token of the matcher
318313
idx: 0,
319-
// We start matching at the span `open` in the source code
320-
sp_open: open,
321314

322315
// Initialize `matches` to a bunch of empty `Vec`s -- one for each metavar in `top_elts`.
323316
// `match_lo` for `top_elts` is 0 and `match_hi` is `matches.len()`. `match_cur` is 0 since
@@ -355,7 +348,7 @@ fn initial_matcher_pos<'root, 'tt>(ms: &'tt [TokenTree], open: Span) -> MatcherP
355348
/// token tree it was derived from.
356349
#[derive(Debug, Clone)]
357350
crate enum NamedMatch {
358-
MatchedSeq(Lrc<NamedMatchVec>, DelimSpan),
351+
MatchedSeq(Lrc<NamedMatchVec>),
359352
MatchedNonterminal(Lrc<Nonterminal>),
360353
}
361354

@@ -497,8 +490,7 @@ fn inner_parse_loop<'root, 'tt>(
497490
// Add matches from this repetition to the `matches` of `up`
498491
for idx in item.match_lo..item.match_hi {
499492
let sub = item.matches[idx].clone();
500-
let span = DelimSpan::from_pair(item.sp_open, token.span);
501-
new_pos.push_match(idx, MatchedSeq(sub, span));
493+
new_pos.push_match(idx, MatchedSeq(sub));
502494
}
503495

504496
// Move the "dot" past the repetition in `up`
@@ -552,7 +544,7 @@ fn inner_parse_loop<'root, 'tt>(
552544
new_item.match_cur += seq.num_captures;
553545
new_item.idx += 1;
554546
for idx in item.match_cur..item.match_cur + seq.num_captures {
555-
new_item.push_match(idx, MatchedSeq(Lrc::new(smallvec![]), sp));
547+
new_item.push_match(idx, MatchedSeq(Lrc::new(smallvec![])));
556548
}
557549
cur_items.push(new_item);
558550
}
@@ -568,7 +560,6 @@ fn inner_parse_loop<'root, 'tt>(
568560
match_cur: item.match_cur,
569561
match_hi: item.match_cur + seq.num_captures,
570562
up: Some(item),
571-
sp_open: sp.open,
572563
top_elts: Tt(TokenTree::Sequence(sp, seq)),
573564
})));
574565
}
@@ -663,7 +654,7 @@ pub(super) fn parse(
663654
//
664655
// This MatcherPos instance is allocated on the stack. All others -- and
665656
// there are frequently *no* others! -- are allocated on the heap.
666-
let mut initial = initial_matcher_pos(ms, parser.token.span);
657+
let mut initial = initial_matcher_pos(ms);
667658
let mut cur_items = smallvec![MatcherPosHandle::Ref(&mut initial)];
668659
let mut next_items = Vec::new();
669660

src/libsyntax_expand/mbe/macro_rules.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ pub fn compile_declarative_macro(
379379

380380
// Extract the arguments:
381381
let lhses = match argument_map[&lhs_nm] {
382-
MatchedSeq(ref s, _) => s
382+
MatchedSeq(ref s) => s
383383
.iter()
384384
.map(|m| {
385385
if let MatchedNonterminal(ref nt) = *m {
@@ -402,7 +402,7 @@ pub fn compile_declarative_macro(
402402
};
403403

404404
let rhses = match argument_map[&rhs_nm] {
405-
MatchedSeq(ref s, _) => s
405+
MatchedSeq(ref s) => s
406406
.iter()
407407
.map(|m| {
408408
if let MatchedNonterminal(ref nt) = *m {

src/libsyntax_expand/mbe/transcribe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ fn lookup_cur_matched<'a>(
299299
for &(idx, _) in repeats {
300300
match matched {
301301
MatchedNonterminal(_) => break,
302-
MatchedSeq(ref ads, _) => matched = ads.get(idx).unwrap(),
302+
MatchedSeq(ref ads) => matched = ads.get(idx).unwrap(),
303303
}
304304
}
305305

@@ -382,7 +382,7 @@ fn lockstep_iter_size(
382382
match lookup_cur_matched(name, interpolations, repeats) {
383383
Some(matched) => match matched {
384384
MatchedNonterminal(_) => LockstepIterSize::Unconstrained,
385-
MatchedSeq(ref ads, _) => LockstepIterSize::Constraint(ads.len(), name),
385+
MatchedSeq(ref ads) => LockstepIterSize::Constraint(ads.len(), name),
386386
},
387387
_ => LockstepIterSize::Unconstrained,
388388
}

0 commit comments

Comments
 (0)