Skip to content

Commit 191ef36

Browse files
committed
make target_feature cfg computation not iterate over the same vector again and again
1 parent 648e5e1 commit 191ef36

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ pub(crate) fn check_tied_features(
297297
/// Used to generate cfg variables and apply features
298298
/// Must express features in the way Rust understands them
299299
pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
300-
let mut features = vec![];
300+
let mut features: FxHashSet<Symbol> = Default::default();
301301

302302
// Add base features for the target.
303303
// We do *not* add the -Ctarget-features there, and instead duplicate the logic for that below.
@@ -306,7 +306,7 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
306306
// the target CPU, that is still expanded to target features (with all their implied features) by
307307
// LLVM.
308308
let target_machine = create_informational_target_machine(sess, true);
309-
// Compute which of the known target features are enables in the 'base' target machine.
309+
// Compute which of the known target features are enabled in the 'base' target machine.
310310
features.extend(
311311
sess.target
312312
.known_target_features()
@@ -343,9 +343,12 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
343343
if enabled {
344344
features.extend(sess.target.implied_target_features(std::iter::once(feature)));
345345
} else {
346-
features.retain(|f| {
347-
!sess.target.implied_target_features(std::iter::once(*f)).contains(&feature)
348-
});
346+
// We don't care about the order in `features` since the only thing we use it for is the
347+
// `features.contains` below.
348+
#[allow(rustc::potential_query_instability)]
349+
for feature_to_remove in sess.target.implied_target_features(std::iter::once(feature)) {
350+
features.remove(&feature_to_remove);
351+
}
349352
}
350353
}
351354

0 commit comments

Comments
 (0)