From 9f0306fbcc091148602c04df7286ddec154d4150 Mon Sep 17 00:00:00 2001 From: Tunglies Date: Sat, 31 Jan 2026 21:48:00 +0800 Subject: [PATCH] refactor: rewrite some `&String` to `&str` (#14857) * perf(tauri-build): refactor find_icon to use &str to remove unnecessary clones * refactor(perf-tauri-build): remove obsolete changelog for find_icon refactor * refactor(tauri-build): inline find_icon logic to simplify window icon path retrieval * refactor(context): update find_icon predicate to use &str * refactor(context): simplify predicate in find_icon to accept &&String * Update crates/tauri-build/src/lib.rs Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com> --------- Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com> --- crates/tauri-build/src/lib.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/crates/tauri-build/src/lib.rs b/crates/tauri-build/src/lib.rs index 42c9275b4..ddfac0cc5 100644 --- a/crates/tauri-build/src/lib.rs +++ b/crates/tauri-build/src/lib.rs @@ -57,7 +57,7 @@ fn copy_binaries( binaries: ResourcePaths, target_triple: &str, path: &Path, - package_name: Option<&String>, + package_name: Option<&str>, ) -> Result<()> { for src in binaries { let src = src?; @@ -529,7 +529,7 @@ pub fn try_build(attributes: Attributes) -> Result<()> { ResourcePaths::new(&external_binaries(paths, &target_triple, &target), true), &target_triple, target_dir, - manifest.package.as_ref().map(|p| &p.name), + manifest.package.as_ref().map(|p| p.name.as_ref()), )?; } @@ -587,21 +587,19 @@ pub fn try_build(attributes: Attributes) -> Result<()> { use semver::Version; use tauri_winres::{VersionInfo, WindowsResource}; - fn find_icon bool>(config: &Config, predicate: F, default: &str) -> PathBuf { - let icon_path = config - .bundle - .icon - .iter() - .find(|i| predicate(i)) - .cloned() - .unwrap_or_else(|| default.to_string()); - icon_path.into() - } - let window_icon_path = attributes .windows_attributes .window_icon_path - .unwrap_or_else(|| find_icon(&config, |i| i.ends_with(".ico"), "icons/icon.ico")); + .unwrap_or_else(|| { + config + .bundle + .icon + .iter() + .find(|i| i.ends_with(".ico")) + .map(AsRef::as_ref) + .unwrap_or("icons/icon.ico") + .into() + }); let mut res = WindowsResource::new();