From e2431baedb8a8b08b80247c9e90a528ef9498b8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Sun, 18 Aug 2024 10:44:31 +0200 Subject: [PATCH] Do not collect all config symbols into a vec needlessly --- esp-hal/build.rs | 4 ++-- esp-metadata/src/lib.rs | 28 +++++++++------------------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/esp-hal/build.rs b/esp-hal/build.rs index 53d29277066..551726ad6f5 100644 --- a/esp-hal/build.rs +++ b/esp-hal/build.rs @@ -67,7 +67,7 @@ fn main() -> Result<(), Box> { config.define_symbols(); #[allow(unused_mut)] - let mut config_symbols = config.all(); + let mut config_symbols = config.all().collect::>(); #[cfg(feature = "flip-link")] config_symbols.push("flip-link".to_owned()); @@ -135,7 +135,7 @@ fn main() -> Result<(), Box> { // Helper Functions fn copy_dir_all( - config_symbols: &Vec, + config_symbols: &[String], src: impl AsRef, dst: impl AsRef, ) -> std::io::Result<()> { diff --git a/esp-metadata/src/lib.rs b/esp-metadata/src/lib.rs index 9df635e9781..47c4351bd94 100644 --- a/esp-metadata/src/lib.rs +++ b/esp-metadata/src/lib.rs @@ -210,36 +210,26 @@ impl Config { } /// All configuration values for the device. - pub fn all(&self) -> Vec { + pub fn all(&self) -> impl Iterator { [ - vec![ - self.device.name.clone(), - self.device.arch.to_string(), - self.device.cores.to_string(), - ], - self.device.peripherals.clone(), - self.device.symbols.clone(), + self.device.name.clone(), + self.device.arch.to_string(), + self.device.cores.to_string(), ] - .concat() + .into_iter() + .chain(self.device.peripherals.clone()) + .chain(self.device.symbols.clone()) } /// Does the configuration contain `item`? pub fn contains(&self, item: &String) -> bool { - self.all().contains(item) + self.all().any(|i| &i == item) } /// Define all symbols for a given configuration. pub fn define_symbols(&self) { // Define all necessary configuration symbols for the configured device: - println!("cargo:rustc-cfg={}", self.name()); - println!("cargo:rustc-cfg={}", self.arch()); - println!("cargo:rustc-cfg={}", self.cores()); - - for peripheral in self.peripherals() { - println!("cargo:rustc-cfg={peripheral}"); - } - - for symbol in self.symbols() { + for symbol in self.all() { println!("cargo:rustc-cfg={symbol}"); } }