Skip to content

Commit 4ecd7e6

Browse files
committed
Auto merge of rust-lang#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)
2 parents a48e0e1 + 90499d4 commit 4ecd7e6

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

crates/mbe/src/benchmark.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn invocation_fixtures(rules: &FxHashMap<String, DeclarativeMacro>) -> Vec<(Stri
7979
let mut res = Vec::new();
8080

8181
for (name, it) in rules {
82-
for rule in &it.rules {
82+
for rule in it.rules.iter() {
8383
// Generate twice
8484
for _ in 0..2 {
8585
// The input are generated by filling the `Op` randomly.

crates/mbe/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl fmt::Display for ExpandError {
104104
/// and `$()*` have special meaning (see `Var` and `Repeat` data structures)
105105
#[derive(Clone, Debug, PartialEq, Eq)]
106106
pub struct DeclarativeMacro {
107-
rules: Vec<Rule>,
107+
rules: Box<[Rule]>,
108108
/// Highest id of the token we have in TokenMap
109109
shift: Shift,
110110
// This is used for correctly determining the behavior of the pat fragment
@@ -217,7 +217,7 @@ impl DeclarativeMacro {
217217
validate(lhs)?;
218218
}
219219

220-
Ok(DeclarativeMacro { rules, shift: Shift::new(tt), is_2021 })
220+
Ok(DeclarativeMacro { rules: rules.into_boxed_slice(), shift: Shift::new(tt), is_2021 })
221221
}
222222

223223
/// The new, unstable `macro m {}` flavor.
@@ -250,7 +250,7 @@ impl DeclarativeMacro {
250250
validate(lhs)?;
251251
}
252252

253-
Ok(DeclarativeMacro { rules, shift: Shift::new(tt), is_2021 })
253+
Ok(DeclarativeMacro { rules: rules.into_boxed_slice(), shift: Shift::new(tt), is_2021 })
254254
}
255255

256256
pub fn expand(&self, tt: &tt::Subtree) -> ExpandResult<tt::Subtree> {

crates/mbe/src/parser.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::{tt, tt_iter::TtIter, ParseError};
2020
/// Stuff to the right is a [`MetaTemplate`] template which is used to produce
2121
/// output.
2222
#[derive(Clone, Debug, PartialEq, Eq)]
23-
pub(crate) struct MetaTemplate(pub(crate) Vec<Op>);
23+
pub(crate) struct MetaTemplate(pub(crate) Box<[Op]>);
2424

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

47-
Ok(MetaTemplate(res))
47+
Ok(MetaTemplate(res.into_boxed_slice()))
4848
}
4949
}
5050

0 commit comments

Comments
 (0)