Skip to content

Commit

Permalink
Optimize CratesToml::append_to_path: Eliminate metadata.bins.clone()
Browse files Browse the repository at this point in the history
Signed-off-by: Jiahao XU <[email protected]>
  • Loading branch information
NobodyXu committed Dec 19, 2022
1 parent 244b55b commit 6ff3ba7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions crates/binstalk-manifests/src/cargo_crates_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::{
path::{Path, PathBuf},
};

use beef::Cow;
use compact_str::CompactString;
use fs_lock::FileLock;
use home::cargo_home;
Expand All @@ -31,12 +32,12 @@ mod crate_version_source;
use crate_version_source::*;

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CratesToml {
pub struct CratesToml<'a> {
#[serde(with = "tuple_vec_map")]
v1: Vec<(String, Vec<CompactString>)>,
v1: Vec<(String, Cow<'a, [CompactString]>)>,
}

impl CratesToml {
impl CratesToml<'_> {
pub fn default_path() -> Result<PathBuf, CratesTomlParseError> {
Ok(cargo_home()?.join(".crates.toml"))
}
Expand All @@ -59,7 +60,7 @@ impl CratesToml {
/// Only use it when you know that the crate is not in the manifest.
/// Otherwise, you need to call [`CratesToml::remove`] first.
pub fn insert(&mut self, cvs: &CrateVersionSource, bins: Vec<CompactString>) {
self.v1.push((cvs.to_string(), bins));
self.v1.push((cvs.to_string(), Cow::owned(bins)));
}

pub fn remove(&mut self, name: &str) {
Expand Down Expand Up @@ -115,7 +116,7 @@ impl CratesToml {
c1.remove(name);
c1.v1.push((
format!("{name} {version} ({source})"),
metadata.bins.clone(),
Cow::borrowed(&metadata.bins),
));
}

Expand Down

0 comments on commit 6ff3ba7

Please sign in to comment.