Skip to content

Commit

Permalink
Auto merge of rust-lang#14720 - Veykril:boxed-slices, r=Veykril
Browse files Browse the repository at this point in the history
internal: Use boxed slices instead ovecs in decl macros

saves another 10 mb on self (since we didn't shrink the vecs)
  • Loading branch information
bors committed May 2, 2023
2 parents a48e0e1 + 90499d4 commit 4ecd7e6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/mbe/src/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn invocation_fixtures(rules: &FxHashMap<String, DeclarativeMacro>) -> Vec<(Stri
let mut res = Vec::new();

for (name, it) in rules {
for rule in &it.rules {
for rule in it.rules.iter() {
// Generate twice
for _ in 0..2 {
// The input are generated by filling the `Op` randomly.
Expand Down
6 changes: 3 additions & 3 deletions crates/mbe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl fmt::Display for ExpandError {
/// and `$()*` have special meaning (see `Var` and `Repeat` data structures)
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct DeclarativeMacro {
rules: Vec<Rule>,
rules: Box<[Rule]>,
/// Highest id of the token we have in TokenMap
shift: Shift,
// This is used for correctly determining the behavior of the pat fragment
Expand Down Expand Up @@ -217,7 +217,7 @@ impl DeclarativeMacro {
validate(lhs)?;
}

Ok(DeclarativeMacro { rules, shift: Shift::new(tt), is_2021 })
Ok(DeclarativeMacro { rules: rules.into_boxed_slice(), shift: Shift::new(tt), is_2021 })
}

/// The new, unstable `macro m {}` flavor.
Expand Down Expand Up @@ -250,7 +250,7 @@ impl DeclarativeMacro {
validate(lhs)?;
}

Ok(DeclarativeMacro { rules, shift: Shift::new(tt), is_2021 })
Ok(DeclarativeMacro { rules: rules.into_boxed_slice(), shift: Shift::new(tt), is_2021 })
}

pub fn expand(&self, tt: &tt::Subtree) -> ExpandResult<tt::Subtree> {
Expand Down
4 changes: 2 additions & 2 deletions crates/mbe/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{tt, tt_iter::TtIter, ParseError};
/// Stuff to the right is a [`MetaTemplate`] template which is used to produce
/// output.
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct MetaTemplate(pub(crate) Vec<Op>);
pub(crate) struct MetaTemplate(pub(crate) Box<[Op]>);

impl MetaTemplate {
pub(crate) fn parse_pattern(pattern: &tt::Subtree) -> Result<MetaTemplate, ParseError> {
Expand All @@ -44,7 +44,7 @@ impl MetaTemplate {
res.push(op);
}

Ok(MetaTemplate(res))
Ok(MetaTemplate(res.into_boxed_slice()))
}
}

Expand Down

0 comments on commit 4ecd7e6

Please sign in to comment.