From 6ec3cf9abc15368df705b65e20e7e753d565fe71 Mon Sep 17 00:00:00 2001 From: Urgau Date: Sat, 15 Feb 2025 11:53:08 +0100 Subject: Load all builtin targets at once instead of one by one This should give us some performance improvements as we won't need to do the lookup for the _currently_ 287 targets we have. --- compiler/rustc_target/src/spec/mod.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'compiler/rustc_target/src') diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 72600225e7a..2acc4ded5d8 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1662,6 +1662,14 @@ macro_rules! supported_targets { Some(t) } + fn load_all_builtins() -> impl Iterator { + [ + $( targets::$module::target, )+ + ] + .into_iter() + .map(|f| f()) + } + #[cfg(test)] mod tests { // Cannot put this into a separate file without duplication, make an exception. @@ -3360,6 +3368,11 @@ impl Target { } } + /// Load all built-in targets + pub fn builtins() -> impl Iterator { + load_all_builtins() + } + /// Search for a JSON file specifying the given target tuple. /// /// If none is found in `$RUST_TARGET_PATH`, look for a file called `target.json` inside the -- cgit 1.4.1-3-g733a5