From 191ef36737acc9a082c58ee31b5939dba6994c2c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 2 Sep 2024 12:06:28 +0200 Subject: [PATCH] make target_feature cfg computation not iterate over the same vector again and again --- compiler/rustc_codegen_llvm/src/llvm_util.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index 49eaa75be4d3..ffb3867dfbc0 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -297,7 +297,7 @@ pub(crate) fn check_tied_features( /// Used to generate cfg variables and apply features /// Must express features in the way Rust understands them pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec { - let mut features = vec![]; + let mut features: FxHashSet = Default::default(); // Add base features for the target. // 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 { // the target CPU, that is still expanded to target features (with all their implied features) by // LLVM. let target_machine = create_informational_target_machine(sess, true); - // Compute which of the known target features are enables in the 'base' target machine. + // Compute which of the known target features are enabled in the 'base' target machine. features.extend( sess.target .known_target_features() @@ -343,9 +343,12 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec { if enabled { features.extend(sess.target.implied_target_features(std::iter::once(feature))); } else { - features.retain(|f| { - !sess.target.implied_target_features(std::iter::once(*f)).contains(&feature) - }); + // We don't care about the order in `features` since the only thing we use it for is the + // `features.contains` below. + #[allow(rustc::potential_query_instability)] + for feature_to_remove in sess.target.implied_target_features(std::iter::once(feature)) { + features.remove(&feature_to_remove); + } } }