Skip to content

Commit 638d686

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 00d8eb4 commit 638d686

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

compiler/rustc_interface/src/interface.rs

Lines changed: 7 additions & 5 deletions
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};
@@ -66,7 +66,7 @@ pub fn parse_cfgspecs(
6666
cfgspecs: Vec<String>,
6767
) -> FxHashSet<(String, Option<String>)> {
6868
rustc_span::create_default_session_if_not_set_then(move |_| {
69-
let cfg = cfgspecs
69+
cfgspecs
7070
.into_iter()
7171
.map(|s| {
7272
let sess = ParseSess::with_silent_emitter(Some(format!(
@@ -96,7 +96,10 @@ pub fn parse_cfgspecs(
9696
}
9797
MetaItemKind::NameValue(..) | MetaItemKind::Word => {
9898
let ident = meta_item.ident().expect("multi-segment cfg key");
99-
return (ident.name, meta_item.value_str());
99+
return (
100+
ident.name.to_string(),
101+
meta_item.value_str().map(|sym| sym.to_string()),
102+
);
100103
}
101104
}
102105
}
@@ -117,8 +120,7 @@ pub fn parse_cfgspecs(
117120
error!(r#"expected `key` or `key="value"`"#);
118121
}
119122
})
120-
.collect::<CrateConfig>();
121-
cfg.into_iter().map(|(a, b)| (a.to_string(), b.map(|b| b.to_string()))).collect()
123+
.collect::<FxHashSet<_>>()
122124
})
123125
}
124126

0 commit comments

Comments
 (0)