diff --git a/.changes/perf-remove-needless-clone.md b/.changes/perf-remove-needless-clone.md new file mode 100644 index 000000000..3e23288c4 --- /dev/null +++ b/.changes/perf-remove-needless-clone.md @@ -0,0 +1,8 @@ +--- +"tauri-bundler": patch:perf +"tauri-cli": patch:perf +"tauri-macos-sign": patch:perf +"tauri": patch:perf +--- + +perf: remove needless clones in various files for improved performance. No user facing changes. diff --git a/crates/tauri-bundler/src/bundle/macos/app.rs b/crates/tauri-bundler/src/bundle/macos/app.rs index cd7055f30..703973c2b 100644 --- a/crates/tauri-bundler/src/bundle/macos/app.rs +++ b/crates/tauri-bundler/src/bundle/macos/app.rs @@ -65,16 +65,12 @@ pub fn bundle_project(settings: &Settings) -> crate::Result> { log::info!(action = "Bundling"; "{} ({})", app_product_name, app_bundle_path.display()); if app_bundle_path.exists() { - fs::remove_dir_all(&app_bundle_path).fs_context( - "failed to remove old app bundle", - app_bundle_path.to_path_buf(), - )?; + fs::remove_dir_all(&app_bundle_path) + .fs_context("failed to remove old app bundle", &app_bundle_path)?; } let bundle_directory = app_bundle_path.join("Contents"); - fs::create_dir_all(&bundle_directory).fs_context( - "failed to create bundle directory", - bundle_directory.to_path_buf(), - )?; + fs::create_dir_all(&bundle_directory) + .fs_context("failed to create bundle directory", &bundle_directory)?; let resources_dir = bundle_directory.join("Resources"); let bin_dir = bundle_directory.join("MacOS"); @@ -459,20 +455,12 @@ fn copy_frameworks_to_bundle( ) -> crate::Result> { let mut paths = Vec::new(); - let frameworks = settings - .macos() - .frameworks - .as_ref() - .cloned() - .unwrap_or_default(); + let frameworks = settings.macos().frameworks.clone().unwrap_or_default(); if frameworks.is_empty() { return Ok(paths); } let dest_dir = bundle_directory.join("Frameworks"); - fs::create_dir_all(&dest_dir).fs_context( - "failed to create Frameworks directory", - dest_dir.to_path_buf(), - )?; + fs::create_dir_all(&dest_dir).fs_context("failed to create Frameworks directory", &dest_dir)?; for framework in frameworks.iter() { if framework.ends_with(".framework") { let src_path = PathBuf::from(framework); diff --git a/crates/tauri-bundler/src/bundle/macos/ios.rs b/crates/tauri-bundler/src/bundle/macos/ios.rs index e2a028113..ac035127a 100644 --- a/crates/tauri-bundler/src/bundle/macos/ios.rs +++ b/crates/tauri-bundler/src/bundle/macos/ios.rs @@ -44,15 +44,11 @@ pub fn bundle_project(settings: &Settings) -> crate::Result> { log::info!(action = "Bundling"; "{} ({})", app_product_name, app_bundle_path.display()); if app_bundle_path.exists() { - fs::remove_dir_all(&app_bundle_path).fs_context( - "failed to remove old app bundle", - app_bundle_path.to_path_buf(), - )?; + fs::remove_dir_all(&app_bundle_path) + .fs_context("failed to remove old app bundle", &app_bundle_path)?; } - fs::create_dir_all(&app_bundle_path).fs_context( - "failed to create bundle directory", - app_bundle_path.to_path_buf(), - )?; + fs::create_dir_all(&app_bundle_path) + .fs_context("failed to create bundle directory", &app_bundle_path)?; for src in settings.resource_files() { let src = src?; diff --git a/crates/tauri-cli/src/acl/permission/ls.rs b/crates/tauri-cli/src/acl/permission/ls.rs index 7cb7c3d1b..1265c3c24 100644 --- a/crates/tauri-cli/src/acl/permission/ls.rs +++ b/crates/tauri-cli/src/acl/permission/ls.rs @@ -34,7 +34,7 @@ pub fn command(options: Options) -> Result<()> { if acl_manifests_path.exists() { let plugin_manifest_json = read_to_string(&acl_manifests_path) - .fs_context("failed to read plugin manifest", acl_manifests_path.clone())?; + .fs_context("failed to read plugin manifest", acl_manifests_path)?; let acl = serde_json::from_str::>(&plugin_manifest_json) .context("failed to parse plugin manifest as JSON")?; diff --git a/crates/tauri-cli/src/dev/builtin_dev_server.rs b/crates/tauri-cli/src/dev/builtin_dev_server.rs index 067a64f67..1b49058ed 100644 --- a/crates/tauri-cli/src/dev/builtin_dev_server.rs +++ b/crates/tauri-cli/src/dev/builtin_dev_server.rs @@ -155,9 +155,9 @@ fn inject_address(html_bytes: Vec, address: &SocketAddr) -> Vec { } fn fs_read_scoped(path: PathBuf, scope: &Path) -> crate::Result> { - let path = dunce::canonicalize(&path).fs_context("failed to canonicalize path", path.clone())?; + let path = dunce::canonicalize(&path).fs_context("failed to canonicalize path", path)?; if path.starts_with(scope) { - std::fs::read(&path).fs_context("failed to read file", path.clone()) + std::fs::read(&path).fs_context("failed to read file", &path) } else { crate::error::bail!("forbidden path") } diff --git a/crates/tauri-cli/src/helpers/updater_signature.rs b/crates/tauri-cli/src/helpers/updater_signature.rs index 5ec0ebe8a..9367e7bad 100644 --- a/crates/tauri-cli/src/helpers/updater_signature.rs +++ b/crates/tauri-cli/src/helpers/updater_signature.rs @@ -146,10 +146,8 @@ where std::fs::write(&signature_path, encoded_signature.as_bytes()) .fs_context("failed to write signature file", signature_path.clone())?; Ok(( - fs::canonicalize(&signature_path).fs_context( - "failed to canonicalize signature file", - signature_path.clone(), - )?, + fs::canonicalize(&signature_path) + .fs_context("failed to canonicalize signature file", &signature_path)?, signature_box, )) } diff --git a/crates/tauri-cli/src/init.rs b/crates/tauri-cli/src/init.rs index a72137388..a809ba317 100644 --- a/crates/tauri-cli/src/init.rs +++ b/crates/tauri-cli/src/init.rs @@ -78,8 +78,8 @@ impl Options { let package_json_path = PathBuf::from(&self.directory).join("package.json"); let init_defaults = if package_json_path.exists() { - let package_json_text = read_to_string(&package_json_path) - .fs_context("failed to read", package_json_path.clone())?; + let package_json_text = + read_to_string(&package_json_path).fs_context("failed to read", &package_json_path)?; let package_json: crate::PackageJson = serde_json::from_str(&package_json_text).context("failed to parse JSON")?; let (framework, _) = infer_framework(&package_json_text); diff --git a/crates/tauri-cli/src/interface/rust/desktop.rs b/crates/tauri-cli/src/interface/rust/desktop.rs index f5edb4d6e..e747f236b 100644 --- a/crates/tauri-cli/src/interface/rust/desktop.rs +++ b/crates/tauri-cli/src/interface/rust/desktop.rs @@ -335,7 +335,7 @@ fn rename_app( "" }; let new_path = bin_path.with_file_name(format!("{main_binary_name}{extension}")); - fs::rename(&bin_path, &new_path).fs_context("failed to rename app binary", bin_path.clone())?; + fs::rename(&bin_path, &new_path).fs_context("failed to rename app binary", bin_path)?; Ok(new_path) } else { Ok(bin_path) diff --git a/crates/tauri-cli/src/interface/rust/manifest.rs b/crates/tauri-cli/src/interface/rust/manifest.rs index 452aecaaa..03e9768bd 100644 --- a/crates/tauri-cli/src/interface/rust/manifest.rs +++ b/crates/tauri-cli/src/interface/rust/manifest.rs @@ -314,7 +314,7 @@ pub fn rewrite_manifest(config: &Config) -> crate::Result<(Manifest, bool)> { if persist && original_manifest_str != new_manifest_str { std::fs::write(&manifest_path, new_manifest_str) - .fs_context("failed to rewrite Cargo manifest", manifest_path.clone())?; + .fs_context("failed to rewrite Cargo manifest", &manifest_path)?; Ok(( Manifest { inner: manifest, diff --git a/crates/tauri-cli/src/migrate/migrations/v1/manifest.rs b/crates/tauri-cli/src/migrate/migrations/v1/manifest.rs index d4d03f38d..2092651d3 100644 --- a/crates/tauri-cli/src/migrate/migrations/v1/manifest.rs +++ b/crates/tauri-cli/src/migrate/migrations/v1/manifest.rs @@ -21,7 +21,7 @@ pub fn migrate(tauri_dir: &Path) -> Result<()> { migrate_manifest(&mut manifest)?; std::fs::write(&manifest_path, serialize_manifest(&manifest)) - .fs_context("failed to rewrite Cargo manifest", manifest_path.clone())?; + .fs_context("failed to rewrite Cargo manifest", &manifest_path)?; Ok(()) } diff --git a/crates/tauri-cli/src/migrate/migrations/v2_beta.rs b/crates/tauri-cli/src/migrate/migrations/v2_beta.rs index 6910ba116..aad493670 100644 --- a/crates/tauri-cli/src/migrate/migrations/v2_beta.rs +++ b/crates/tauri-cli/src/migrate/migrations/v2_beta.rs @@ -28,10 +28,8 @@ pub fn run() -> Result<()> { migrate_npm_dependencies(frontend_dir)?; - std::fs::write(&manifest_path, serialize_manifest(&manifest)).fs_context( - "failed to rewrite Cargo manifest", - manifest_path.to_path_buf(), - )?; + std::fs::write(&manifest_path, serialize_manifest(&manifest)) + .fs_context("failed to rewrite Cargo manifest", &manifest_path)?; Ok(()) } diff --git a/crates/tauri-cli/src/mobile/ios/build.rs b/crates/tauri-cli/src/mobile/ios/build.rs index 9f4aab42c..3f5b2c1a2 100644 --- a/crates/tauri-cli/src/mobile/ios/build.rs +++ b/crates/tauri-cli/src/mobile/ios/build.rs @@ -311,7 +311,7 @@ pub fn command(options: Options, noise_level: NoiseLevel) -> Result fn normalize_path(path: &Path) -> PathBuf { let mut components = path.components().peekable(); - let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() { + let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().copied() { components.next(); PathBuf::from(c.as_os_str()) } else { @@ -47,7 +47,7 @@ fn normalize_path(path: &Path) -> PathBuf { /// fn normalize_path_no_absolute(path: &Path) -> PathBuf { let mut components = path.components().peekable(); - let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() { + let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().copied() { components.next(); PathBuf::from(c.as_os_str()) } else {