From 0717d8dd0af5b093c81b292e5f1fe9985fe367ab Mon Sep 17 00:00:00 2001 From: Jamie Pine Date: Wed, 10 Dec 2025 14:43:17 -0800 Subject: [PATCH] Refactor code for improved clarity and performance - Updated argument passing in various commands to use a more concise syntax. - Simplified iteration in the ConstantTimeEqNull implementation for better readability. - Enhanced file path checks in EventFilters for temporary and system files. - Added `#[must_use]` attribute to functions in FrameDecoder to indicate their importance. - Replaced `or_insert_with` with `or_default` for cleaner code in phase summary generation. --- apps/tauri/src-tauri/build.rs | 2 +- crates/crypto/src/ct.rs | 2 +- crates/ffmpeg/src/filter_graph.rs | 2 +- crates/ffmpeg/src/frame_decoder.rs | 4 ++-- crates/fs-watcher/src/config.rs | 12 +++++------- crates/job-derive/src/lib.rs | 2 +- crates/log-analyzer/src/output/phase_summary.rs | 2 +- xtask/src/main.rs | 4 ++-- xtask/src/system.rs | 7 +++---- 9 files changed, 17 insertions(+), 20 deletions(-) diff --git a/apps/tauri/src-tauri/build.rs b/apps/tauri/src-tauri/build.rs index 738aae818..5c45ddac6 100644 --- a/apps/tauri/src-tauri/build.rs +++ b/apps/tauri/src-tauri/build.rs @@ -17,7 +17,7 @@ fn main() { // Run actool to compile .icon to Assets.car let output = Command::new("xcrun") - .args(&[ + .args([ "actool", &icon_source, "--compile", diff --git a/crates/crypto/src/ct.rs b/crates/crypto/src/ct.rs index 8ce937ab9..b8e0b5606 100644 --- a/crates/crypto/src/ct.rs +++ b/crates/crypto/src/ct.rs @@ -175,7 +175,7 @@ impl ConstantTimeEqNull for [u8] { #[inline] fn ct_eq_null(&self) -> Choice { let mut x = 1u8; - self.iter().for_each(|b| b.cmovne(&0, 0u8, &mut x)); + for b in self.iter() { b.cmovne(&0, 0u8, &mut x); } Choice::from(x) } } diff --git a/crates/ffmpeg/src/filter_graph.rs b/crates/ffmpeg/src/filter_graph.rs index e9547f9ab..7590e9ed4 100644 --- a/crates/ffmpeg/src/filter_graph.rs +++ b/crates/ffmpeg/src/filter_graph.rs @@ -241,7 +241,7 @@ fn thumb_scale_filter_args( eprintln!("Warning: Failed to calculate width with pixel aspect ratio"); // Keep the original width as fallback } - }; + } if size != 0 { if height > width { width = (width * size) / height; diff --git a/crates/ffmpeg/src/frame_decoder.rs b/crates/ffmpeg/src/frame_decoder.rs index 800a1eadb..22be0dabd 100644 --- a/crates/ffmpeg/src/frame_decoder.rs +++ b/crates/ffmpeg/src/frame_decoder.rs @@ -92,7 +92,7 @@ impl FrameDecoder { }) } - pub const fn use_embedded(&self) -> bool { + #[must_use] pub const fn use_embedded(&self) -> bool { self.embedded } @@ -224,7 +224,7 @@ impl FrameDecoder { }) } - pub fn get_duration_secs(&self) -> Option { + #[must_use] pub fn get_duration_secs(&self) -> Option { self.format_ctx.duration().map(|duration| { let av_time_base = i64::from(AV_TIME_BASE); #[allow(clippy::cast_precision_loss)] diff --git a/crates/fs-watcher/src/config.rs b/crates/fs-watcher/src/config.rs index 513a175a6..ae3d629d6 100644 --- a/crates/fs-watcher/src/config.rs +++ b/crates/fs-watcher/src/config.rs @@ -110,22 +110,20 @@ impl EventFilters { let path_str = path.to_string_lossy(); // Check temp files - if self.skip_temp_files { - if path_str.contains(".tmp") + if self.skip_temp_files + && (path_str.contains(".tmp") || path_str.contains(".temp") || path_str.ends_with("~") - || path_str.ends_with(".swp") + || path_str.ends_with(".swp")) { return true; } - } // Check system files - if self.skip_system_files { - if path_str.contains(".DS_Store") || path_str.contains("Thumbs.db") { + if self.skip_system_files + && (path_str.contains(".DS_Store") || path_str.contains("Thumbs.db")) { return true; } - } // Check hidden files if self.skip_hidden { diff --git a/crates/job-derive/src/lib.rs b/crates/job-derive/src/lib.rs index 3ddaf421d..82df60874 100644 --- a/crates/job-derive/src/lib.rs +++ b/crates/job-derive/src/lib.rs @@ -28,7 +28,7 @@ pub fn derive_job(input: TokenStream) -> TokenStream { let name = &input.ident; // Ensure this is a struct - let _data = match &input.data { + match &input.data { Data::Struct(DataStruct { .. }) => {} _ => { return syn::Error::new_spanned(&input.ident, "Job can only be derived for structs") diff --git a/crates/log-analyzer/src/output/phase_summary.rs b/crates/log-analyzer/src/output/phase_summary.rs index f8f122a82..407571abf 100644 --- a/crates/log-analyzer/src/output/phase_summary.rs +++ b/crates/log-analyzer/src/output/phase_summary.rs @@ -96,7 +96,7 @@ pub fn generate_phase_summary(analyzer: &LogAnalyzer, phase_duration_secs: u64) .join("::"); by_module .entry(module_base) - .or_insert_with(Vec::new) + .or_default() .push((template_id, count)); } diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 1b6aee80a..870301239 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -239,7 +239,7 @@ fn build_ios() -> Result<()> { println!("Building for iOS {} ({})...", platform, arch); let status = Command::new("cargo") - .args(&["build", "--release", "--target", target]) + .args(["build", "--release", "--target", target]) .current_dir(&ios_core_dir) .env("IPHONEOS_DEPLOYMENT_TARGET", "12.0") .status() @@ -284,7 +284,7 @@ fn build_ios() -> Result<()> { // Create universal simulator library using lipo println!("Creating universal simulator library..."); let status = Command::new("lipo") - .args(&[ + .args([ "-create", ios_core_dir .join(format!( diff --git a/xtask/src/system.rs b/xtask/src/system.rs index 887087114..eb7cbb4ef 100644 --- a/xtask/src/system.rs +++ b/xtask/src/system.rs @@ -99,7 +99,7 @@ fn detect_libc() -> Result { /// Get list of installed Rust targets pub fn get_rust_targets() -> Result> { let output = Command::new("rustup") - .args(&["target", "list", "--installed"]) + .args(["target", "list", "--installed"]) .output()?; if !output.status.success() { @@ -129,10 +129,9 @@ pub fn get_best_linker() -> Option { return Some("lld".to_string()); } } - } else if cfg!(target_os = "windows") { - if has_linker("lld-link") { + } else if cfg!(target_os = "windows") + && has_linker("lld-link") { return Some("lld-link".to_string()); } - } None }