Auto merge of #14720 - Veykril:boxed-slices, r=Veykril

internal: Use boxed slices instead ovecs in decl macros

saves another 10 mb on self (since we didn't shrink the vecs)
This commit is contained in:
bors 2023-05-02 15:05:28 +00:00
commit 4ecd7e6c0d
3 changed files with 6 additions and 6 deletions

View File

@ -79,7 +79,7 @@ fn invocation_fixtures(rules: &FxHashMap<String, DeclarativeMacro>) -> Vec<(Stri
let mut res = Vec::new(); let mut res = Vec::new();
for (name, it) in rules { for (name, it) in rules {
for rule in &it.rules { for rule in it.rules.iter() {
// Generate twice // Generate twice
for _ in 0..2 { for _ in 0..2 {
// The input are generated by filling the `Op` randomly. // The input are generated by filling the `Op` randomly.

View File

@ -104,7 +104,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
/// and `$()*` have special meaning (see `Var` and `Repeat` data structures) /// and `$()*` have special meaning (see `Var` and `Repeat` data structures)
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct DeclarativeMacro { pub struct DeclarativeMacro {
rules: Vec<Rule>, rules: Box<[Rule]>,
/// Highest id of the token we have in TokenMap /// Highest id of the token we have in TokenMap
shift: Shift, shift: Shift,
// This is used for correctly determining the behavior of the pat fragment // This is used for correctly determining the behavior of the pat fragment
@ -217,7 +217,7 @@ pub fn parse_macro_rules(
validate(lhs)?; 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. /// The new, unstable `macro m {}` flavor.
@ -250,7 +250,7 @@ pub fn parse_macro2(tt: &tt::Subtree, is_2021: bool) -> Result<DeclarativeMacro,
validate(lhs)?; 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> { pub fn expand(&self, tt: &tt::Subtree) -> ExpandResult<tt::Subtree> {

View File

@ -20,7 +20,7 @@
/// Stuff to the right is a [`MetaTemplate`] template which is used to produce /// Stuff to the right is a [`MetaTemplate`] template which is used to produce
/// output. /// output.
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct MetaTemplate(pub(crate) Vec<Op>); pub(crate) struct MetaTemplate(pub(crate) Box<[Op]>);
impl MetaTemplate { impl MetaTemplate {
pub(crate) fn parse_pattern(pattern: &tt::Subtree) -> Result<MetaTemplate, ParseError> { pub(crate) fn parse_pattern(pattern: &tt::Subtree) -> Result<MetaTemplate, ParseError> {
@ -44,7 +44,7 @@ fn parse(tt: &tt::Subtree, mode: Mode) -> Result<MetaTemplate, ParseError> {
res.push(op); res.push(op);
} }
Ok(MetaTemplate(res)) Ok(MetaTemplate(res.into_boxed_slice()))
} }
} }