From b681433b9d40ce1d851d22bedb7ccb483bedda06 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Thu, 7 Feb 2019 14:19:06 +0100 Subject: Use `Rc<[Symbol]>` instead of `Vec` to reduce # of allocs --- src/libsyntax/ext/base.rs | 6 +++--- src/libsyntax/ext/derive.rs | 4 ++-- src/libsyntax/ext/expand.rs | 10 +++++----- src/libsyntax/ext/tt/macro_rules.rs | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index ec7d0e423b4..7c6303b3d40 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -622,7 +622,7 @@ pub enum SyntaxExtension { ProcMacro { expander: Box, /// Whitelist of unstable features that are treated as stable inside this macro - allow_internal_unstable: Vec, + allow_internal_unstable: Option>, edition: Edition, }, @@ -642,7 +642,7 @@ pub enum SyntaxExtension { /// directly use `#[unstable]` things. /// /// Only allows things that require a feature gate in the given whitelist - allow_internal_unstable: Vec, + allow_internal_unstable: Option>, /// Whether the contents of the macro can use `unsafe` /// without triggering the `unsafe_code` lint. allow_internal_unsafe: bool, @@ -660,7 +660,7 @@ pub enum SyntaxExtension { IdentTT { expander: Box, span: Option, - allow_internal_unstable: Vec, + allow_internal_unstable: Option>, }, /// An attribute-like procedural macro. TokenStream -> TokenStream. diff --git a/src/libsyntax/ext/derive.rs b/src/libsyntax/ext/derive.rs index 03d68f4257f..6df369133d0 100644 --- a/src/libsyntax/ext/derive.rs +++ b/src/libsyntax/ext/derive.rs @@ -58,10 +58,10 @@ pub fn add_derived_markers(cx: &mut ExtCtxt<'_>, span: Span, traits: &[ast::P call_site: span, def_site: None, format: ExpnFormat::MacroAttribute(Symbol::intern(&pretty_name)), - allow_internal_unstable: vec![ + allow_internal_unstable: Some(vec![ Symbol::intern("rustc_attrs"), Symbol::intern("structural_match"), - ], + ].into()), allow_internal_unsafe: false, local_inner_macros: false, edition: hygiene::default_edition(), diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index d59e5ab6798..60359531b7f 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -558,7 +558,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { call_site: attr.span, def_site: None, format: MacroAttribute(Symbol::intern(&attr.path.to_string())), - allow_internal_unstable: Vec::new(), + allow_internal_unstable: None, allow_internal_unsafe: false, local_inner_macros: false, edition: ext.edition(), @@ -758,7 +758,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { let opt_expanded = match *ext { DeclMacro { ref expander, def_info, edition, .. } => { if let Err(dummy_span) = validate_and_set_expn_info(self, def_info.map(|(_, s)| s), - Vec::new(), false, false, None, + None, false, false, None, edition) { dummy_span } else { @@ -919,7 +919,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { call_site: span, def_site: None, format: MacroAttribute(pretty_name), - allow_internal_unstable: Vec::new(), + allow_internal_unstable: None, allow_internal_unsafe: false, local_inner_macros: false, edition: ext.edition(), @@ -938,12 +938,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> { Some(invoc.fragment_kind.expect_from_annotatables(items)) } BuiltinDerive(func) => { - expn_info.allow_internal_unstable = vec![ + expn_info.allow_internal_unstable = Some(vec![ Symbol::intern("rustc_attrs"), Symbol::intern("derive_clone_copy"), Symbol::intern("derive_eq"), Symbol::intern("libstd_sys_internals"), // RustcDeserialize and RustcSerialize - ]; + ].into()); invoc.expansion_data.mark.set_expn_info(expn_info); let span = span.with_ctxt(self.cx.backtrace()); let mut items = Vec::new(); diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index a79f3271fcb..cc5531c4010 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -377,13 +377,13 @@ pub fn compile( if body.legacy { let allow_internal_unstable = attr::find_by_name(&def.attrs, "allow_internal_unstable") - .map_or(Vec::new(), |attr| attr + .map(|attr| attr .meta_item_list() .map(|list| list.iter() .map(|it| it.name().unwrap_or_else(|| sess.span_diagnostic.span_bug( it.span, "allow internal unstable expects feature names", ))) - .collect() + .collect::>().into() ) .unwrap_or_else(|| { sess.span_diagnostic.span_warn( @@ -391,7 +391,7 @@ pub fn compile( future this will become a hard error. Please use `allow_internal_unstable(\ foo, bar)` to only allow the `foo` and `bar` features", ); - vec![Symbol::intern("allow_internal_unstable_backcompat_hack")] + vec![Symbol::intern("allow_internal_unstable_backcompat_hack")].into() }) ); let allow_internal_unsafe = attr::contains_name(&def.attrs, "allow_internal_unsafe"); -- cgit 1.4.1-3-g733a5