Skip to content

Commit 75e415b

Browse files
committed
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.)
1 parent 32986d8 commit 75e415b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

compiler/rustc_interface/src/interface.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_parse::maybe_new_parser_from_source_str;
1616
use rustc_query_impl::QueryCtxt;
1717
use rustc_query_system::query::print_query_stack;
1818
use rustc_session::config::{self, CheckCfg, ExpectedValues, Input, OutFileName, OutputFilenames};
19-
use rustc_session::parse::{CrateConfig, ParseSess};
19+
use rustc_session::parse::ParseSess;
2020
use rustc_session::CompilerIO;
2121
use rustc_session::Session;
2222
use rustc_session::{lint, EarlyErrorHandler};
@@ -67,7 +67,7 @@ pub fn parse_cfgspecs(
6767
cfgspecs: Vec<String>,
6868
) -> FxHashSet<(String, Option<String>)> {
6969
rustc_span::create_default_session_if_not_set_then(move |_| {
70-
let cfg = cfgspecs
70+
cfgspecs
7171
.into_iter()
7272
.map(|s| {
7373
let sess = ParseSess::with_silent_emitter(Some(format!(
@@ -97,7 +97,10 @@ pub fn parse_cfgspecs(
9797
}
9898
MetaItemKind::NameValue(..) | MetaItemKind::Word => {
9999
let ident = meta_item.ident().expect("multi-segment cfg key");
100-
return (ident.name, meta_item.value_str());
100+
return (
101+
ident.name.to_string(),
102+
meta_item.value_str().map(|sym| sym.to_string()),
103+
);
101104
}
102105
}
103106
}
@@ -118,8 +121,7 @@ pub fn parse_cfgspecs(
118121
error!(r#"expected `key` or `key="value"`"#);
119122
}
120123
})
121-
.collect::<CrateConfig>();
122-
cfg.into_iter().map(|(a, b)| (a.to_string(), b.map(|b| b.to_string()))).collect()
124+
.collect::<FxHashSet<_>>()
123125
})
124126
}
125127

0 commit comments

Comments
 (0)