Skip to content

Commit ee3cc4a

Browse files
TungliesFabianLars
andauthored
perf: remove needless clones in various files for improved performance (#14475)
Co-authored-by: Fabian-Lars <[email protected]>
1 parent b5ef603 commit ee3cc4a

File tree

14 files changed

+34
-46
lines changed

14 files changed

+34
-46
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"tauri-bundler": patch:perf
3+
"tauri-cli": patch:perf
4+
"tauri-macos-sign": patch:perf
5+
"tauri": patch:perf
6+
---
7+
8+
perf: remove needless clones in various files for improved performance. No user facing changes.

crates/tauri-bundler/src/bundle/macos/app.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,12 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
6565
log::info!(action = "Bundling"; "{} ({})", app_product_name, app_bundle_path.display());
6666

6767
if app_bundle_path.exists() {
68-
fs::remove_dir_all(&app_bundle_path).fs_context(
69-
"failed to remove old app bundle",
70-
app_bundle_path.to_path_buf(),
71-
)?;
68+
fs::remove_dir_all(&app_bundle_path)
69+
.fs_context("failed to remove old app bundle", &app_bundle_path)?;
7270
}
7371
let bundle_directory = app_bundle_path.join("Contents");
74-
fs::create_dir_all(&bundle_directory).fs_context(
75-
"failed to create bundle directory",
76-
bundle_directory.to_path_buf(),
77-
)?;
72+
fs::create_dir_all(&bundle_directory)
73+
.fs_context("failed to create bundle directory", &bundle_directory)?;
7874

7975
let resources_dir = bundle_directory.join("Resources");
8076
let bin_dir = bundle_directory.join("MacOS");
@@ -459,20 +455,12 @@ fn copy_frameworks_to_bundle(
459455
) -> crate::Result<Vec<SignTarget>> {
460456
let mut paths = Vec::new();
461457

462-
let frameworks = settings
463-
.macos()
464-
.frameworks
465-
.as_ref()
466-
.cloned()
467-
.unwrap_or_default();
458+
let frameworks = settings.macos().frameworks.clone().unwrap_or_default();
468459
if frameworks.is_empty() {
469460
return Ok(paths);
470461
}
471462
let dest_dir = bundle_directory.join("Frameworks");
472-
fs::create_dir_all(&dest_dir).fs_context(
473-
"failed to create Frameworks directory",
474-
dest_dir.to_path_buf(),
475-
)?;
463+
fs::create_dir_all(&dest_dir).fs_context("failed to create Frameworks directory", &dest_dir)?;
476464
for framework in frameworks.iter() {
477465
if framework.ends_with(".framework") {
478466
let src_path = PathBuf::from(framework);

crates/tauri-bundler/src/bundle/macos/ios.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,11 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
4444
log::info!(action = "Bundling"; "{} ({})", app_product_name, app_bundle_path.display());
4545

4646
if app_bundle_path.exists() {
47-
fs::remove_dir_all(&app_bundle_path).fs_context(
48-
"failed to remove old app bundle",
49-
app_bundle_path.to_path_buf(),
50-
)?;
47+
fs::remove_dir_all(&app_bundle_path)
48+
.fs_context("failed to remove old app bundle", &app_bundle_path)?;
5149
}
52-
fs::create_dir_all(&app_bundle_path).fs_context(
53-
"failed to create bundle directory",
54-
app_bundle_path.to_path_buf(),
55-
)?;
50+
fs::create_dir_all(&app_bundle_path)
51+
.fs_context("failed to create bundle directory", &app_bundle_path)?;
5652

5753
for src in settings.resource_files() {
5854
let src = src?;

crates/tauri-cli/src/acl/permission/ls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn command(options: Options) -> Result<()> {
3434

3535
if acl_manifests_path.exists() {
3636
let plugin_manifest_json = read_to_string(&acl_manifests_path)
37-
.fs_context("failed to read plugin manifest", acl_manifests_path.clone())?;
37+
.fs_context("failed to read plugin manifest", acl_manifests_path)?;
3838
let acl = serde_json::from_str::<BTreeMap<String, Manifest>>(&plugin_manifest_json)
3939
.context("failed to parse plugin manifest as JSON")?;
4040

crates/tauri-cli/src/dev/builtin_dev_server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ fn inject_address(html_bytes: Vec<u8>, address: &SocketAddr) -> Vec<u8> {
155155
}
156156

157157
fn fs_read_scoped(path: PathBuf, scope: &Path) -> crate::Result<Vec<u8>> {
158-
let path = dunce::canonicalize(&path).fs_context("failed to canonicalize path", path.clone())?;
158+
let path = dunce::canonicalize(&path).fs_context("failed to canonicalize path", path)?;
159159
if path.starts_with(scope) {
160-
std::fs::read(&path).fs_context("failed to read file", path.clone())
160+
std::fs::read(&path).fs_context("failed to read file", &path)
161161
} else {
162162
crate::error::bail!("forbidden path")
163163
}

crates/tauri-cli/src/helpers/updater_signature.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,8 @@ where
146146
std::fs::write(&signature_path, encoded_signature.as_bytes())
147147
.fs_context("failed to write signature file", signature_path.clone())?;
148148
Ok((
149-
fs::canonicalize(&signature_path).fs_context(
150-
"failed to canonicalize signature file",
151-
signature_path.clone(),
152-
)?,
149+
fs::canonicalize(&signature_path)
150+
.fs_context("failed to canonicalize signature file", &signature_path)?,
153151
signature_box,
154152
))
155153
}

crates/tauri-cli/src/init.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ impl Options {
7878
let package_json_path = PathBuf::from(&self.directory).join("package.json");
7979

8080
let init_defaults = if package_json_path.exists() {
81-
let package_json_text = read_to_string(&package_json_path)
82-
.fs_context("failed to read", package_json_path.clone())?;
81+
let package_json_text =
82+
read_to_string(&package_json_path).fs_context("failed to read", &package_json_path)?;
8383
let package_json: crate::PackageJson =
8484
serde_json::from_str(&package_json_text).context("failed to parse JSON")?;
8585
let (framework, _) = infer_framework(&package_json_text);

crates/tauri-cli/src/interface/rust/desktop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ fn rename_app(
335335
""
336336
};
337337
let new_path = bin_path.with_file_name(format!("{main_binary_name}{extension}"));
338-
fs::rename(&bin_path, &new_path).fs_context("failed to rename app binary", bin_path.clone())?;
338+
fs::rename(&bin_path, &new_path).fs_context("failed to rename app binary", bin_path)?;
339339
Ok(new_path)
340340
} else {
341341
Ok(bin_path)

crates/tauri-cli/src/interface/rust/manifest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ pub fn rewrite_manifest(config: &Config) -> crate::Result<(Manifest, bool)> {
314314

315315
if persist && original_manifest_str != new_manifest_str {
316316
std::fs::write(&manifest_path, new_manifest_str)
317-
.fs_context("failed to rewrite Cargo manifest", manifest_path.clone())?;
317+
.fs_context("failed to rewrite Cargo manifest", &manifest_path)?;
318318
Ok((
319319
Manifest {
320320
inner: manifest,

crates/tauri-cli/src/migrate/migrations/v1/manifest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn migrate(tauri_dir: &Path) -> Result<()> {
2121
migrate_manifest(&mut manifest)?;
2222

2323
std::fs::write(&manifest_path, serialize_manifest(&manifest))
24-
.fs_context("failed to rewrite Cargo manifest", manifest_path.clone())?;
24+
.fs_context("failed to rewrite Cargo manifest", &manifest_path)?;
2525

2626
Ok(())
2727
}

0 commit comments

Comments
 (0)