From a8512d7d51c995934e9173cdc5d79300712acee1 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 12 Dec 2023 15:56:15 -0500 Subject: [PATCH] Remove one string clone (#626) --- crates/puffin-build/src/lib.rs | 21 +++++++++++++-------- crates/puffin-dev/src/build.rs | 3 +-- crates/puffin-dispatch/src/lib.rs | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/crates/puffin-build/src/lib.rs b/crates/puffin-build/src/lib.rs index 9643b3dd80a7..8bd1f45c711e 100644 --- a/crates/puffin-build/src/lib.rs +++ b/crates/puffin-build/src/lib.rs @@ -98,7 +98,11 @@ impl Display for MissingHeaderCause { } impl Error { - fn from_command_output(message: String, output: &Output, package_id: &str) -> Self { + fn from_command_output( + message: String, + output: &Output, + package_id: impl Into, + ) -> Self { let stdout = String::from_utf8_lossy(&output.stdout).trim().to_string(); let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string(); @@ -115,7 +119,7 @@ impl Error { stderr, missing_header_cause: MissingHeaderCause { header, - package_id: package_id.to_string(), + package_id: package_id.into(), }, }; } @@ -250,7 +254,7 @@ impl SourceBuild { interpreter: &Interpreter, build_context: &impl BuildContext, source_build_context: SourceBuildContext, - source_dist: &str, + source_dist: String, build_kind: BuildKind, ) -> Result { let temp_dir = tempdir()?; @@ -349,7 +353,7 @@ impl SourceBuild { &venv, pep517_backend, build_context, - source_dist, + &source_dist, build_kind, ) .await?; @@ -367,14 +371,14 @@ impl SourceBuild { venv, build_kind, metadata_directory: None, - package_id: source_dist.to_string(), + package_id: source_dist, }) } /// Try calling `prepare_metadata_for_build_wheel` to get the metadata without executing the /// actual build. /// - /// TODO(konstin): Return the actual metadata instead of the dist-info dir + /// TODO(konstin): Return the actual metadata instead of the dist-info dir. pub async fn get_metadata_without_build(&mut self) -> Result, Error> { // setup.py builds don't support this. let Some(pep517_backend) = &self.pep517_backend else { @@ -415,7 +419,8 @@ impl SourceBuild { return Err(Error::from_command_output( "Build backend failed to determine metadata through `prepare_metadata_for_build_wheel`".to_string(), &output, - &self.package_id)); + &self.package_id, + )); } let message = output .stdout @@ -612,7 +617,7 @@ async fn create_pep517_build_environment( drop(span); if !output.status.success() { return Err(Error::from_command_output( - format!("Build backend failed to determine extra requires with `build_{build_kind}()`",), + format!("Build backend failed to determine extra requires with `build_{build_kind}()`"), &output, package_id, )); diff --git a/crates/puffin-dev/src/build.rs b/crates/puffin-dev/src/build.rs index 72f1f4930d8e..83ad145265b1 100644 --- a/crates/puffin-dev/src/build.rs +++ b/crates/puffin-dev/src/build.rs @@ -69,8 +69,7 @@ pub(crate) async fn build(args: BuildArgs) -> Result { build_dispatch.interpreter(), &build_dispatch, SourceBuildContext::default(), - // Good enough for the dev command - &args.sdist.display().to_string(), + args.sdist.display().to_string(), build_kind, ) .await?; diff --git a/crates/puffin-dispatch/src/lib.rs b/crates/puffin-dispatch/src/lib.rs index 88a4a0aedf41..69ff825c8fba 100644 --- a/crates/puffin-dispatch/src/lib.rs +++ b/crates/puffin-dispatch/src/lib.rs @@ -231,7 +231,7 @@ impl BuildContext for BuildDispatch { &self.interpreter, self, self.source_build_context.clone(), - source_dist, + source_dist.to_string(), BuildKind::Wheel, ) .await?;