about summary refs log tree commit diff
path: root/compiler/rustc_interface/src
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2023-10-27 15:54:14 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2023-10-28 09:03:51 +1100
commit75e415ba86cc16ee5c0fd3c9007c94ea98995ab3 (patch)
tree8b8a7cb1bdf3cb7b50959604ecab4f3fc5b951b6 /compiler/rustc_interface/src
parent32986d895f9105de00a87d7f3d8897477ab64803 (diff)
Optimize `parse_cfgspecs`.
In `parse_cfg`, we now construct a `FxHashSet<String>` directly instead of
constructing a `FxHashSet<Symbol>` and then immediately converting it to a
`FxHashSet<String>`(!)

(The type names made this behaviour non-obvious. The next commit will
make the type names clearer.)
Diffstat (limited to 'compiler/rustc_interface/src')
-rw-r--r--compiler/rustc_interface/src/interface.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs
index 87badcbdf15..26d7d26c31c 100644
--- a/compiler/rustc_interface/src/interface.rs
+++ b/compiler/rustc_interface/src/interface.rs
@@ -16,7 +16,7 @@ use rustc_parse::maybe_new_parser_from_source_str;
 use rustc_query_impl::QueryCtxt;
 use rustc_query_system::query::print_query_stack;
 use rustc_session::config::{self, CheckCfg, ExpectedValues, Input, OutFileName, OutputFilenames};
-use rustc_session::parse::{CrateConfig, ParseSess};
+use rustc_session::parse::ParseSess;
 use rustc_session::CompilerIO;
 use rustc_session::Session;
 use rustc_session::{lint, EarlyErrorHandler};
@@ -67,7 +67,7 @@ pub fn parse_cfgspecs(
     cfgspecs: Vec<String>,
 ) -> FxHashSet<(String, Option<String>)> {
     rustc_span::create_default_session_if_not_set_then(move |_| {
-        let cfg = cfgspecs
+        cfgspecs
             .into_iter()
             .map(|s| {
                 let sess = ParseSess::with_silent_emitter(Some(format!(
@@ -97,7 +97,10 @@ pub fn parse_cfgspecs(
                                 }
                                 MetaItemKind::NameValue(..) | MetaItemKind::Word => {
                                     let ident = meta_item.ident().expect("multi-segment cfg key");
-                                    return (ident.name, meta_item.value_str());
+                                    return (
+                                        ident.name.to_string(),
+                                        meta_item.value_str().map(|sym| sym.to_string()),
+                                    );
                                 }
                             }
                         }
@@ -118,8 +121,7 @@ pub fn parse_cfgspecs(
                     error!(r#"expected `key` or `key="value"`"#);
                 }
             })
-            .collect::<CrateConfig>();
-        cfg.into_iter().map(|(a, b)| (a.to_string(), b.map(|b| b.to_string()))).collect()
+            .collect::<FxHashSet<_>>()
     })
 }