1
Fork 0

Pass a slice instead of a Vec to transcribe.

It avoids some unnecessary allocations.
This commit is contained in:
Nicholas Nethercote 2022-04-11 09:52:34 +10:00
parent 1a7006482e
commit 2657d8f7b3
2 changed files with 3 additions and 3 deletions

View file

@ -263,14 +263,14 @@ fn generic_extension<'cx, 'tt>(
// Ignore the delimiters on the RHS. // Ignore the delimiters on the RHS.
let rhs = match &rhses[i] { let rhs = match &rhses[i] {
mbe::TokenTree::Delimited(_, delimited) => delimited.tts.to_vec(), mbe::TokenTree::Delimited(_, delimited) => &delimited.tts,
_ => cx.span_bug(sp, "malformed macro rhs"), _ => cx.span_bug(sp, "malformed macro rhs"),
}; };
let arm_span = rhses[i].span(); let arm_span = rhses[i].span();
let rhs_spans = rhs.iter().map(|t| t.span()).collect::<Vec<_>>(); let rhs_spans = rhs.iter().map(|t| t.span()).collect::<Vec<_>>();
// rhs has holes ( `$id` and `$(...)` that need filled) // rhs has holes ( `$id` and `$(...)` that need filled)
let mut tts = match transcribe(cx, &named_matches, rhs, transparency) { let mut tts = match transcribe(cx, &named_matches, &rhs, transparency) {
Ok(tts) => tts, Ok(tts) => tts,
Err(mut err) => { Err(mut err) => {
err.emit(); err.emit();

View file

@ -85,7 +85,7 @@ impl<'a> Iterator for Frame<'a> {
pub(super) fn transcribe<'a>( pub(super) fn transcribe<'a>(
cx: &ExtCtxt<'a>, cx: &ExtCtxt<'a>,
interp: &FxHashMap<MacroRulesNormalizedIdent, NamedMatch>, interp: &FxHashMap<MacroRulesNormalizedIdent, NamedMatch>,
src: Vec<mbe::TokenTree>, src: &[mbe::TokenTree],
transparency: Transparency, transparency: Transparency,
) -> PResult<'a, TokenStream> { ) -> PResult<'a, TokenStream> {
// Nothing for us to transcribe... // Nothing for us to transcribe...