Use CompactString for fields of CrateName

Since most of the time, they are shorter than 24 bytes.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-08-02 22:17:11 +10:00
parent caeb49ce33
commit d430c077d4
No known key found for this signature in database
GPG key ID: 591C0B03040416D6
2 changed files with 8 additions and 6 deletions

View file

@ -4,6 +4,7 @@ use std::{
};
use cargo_toml::{Package, Product};
use compact_str::CompactString;
use log::{debug, error, info, warn};
use miette::{miette, Result};
use reqwest::Client;
@ -19,7 +20,7 @@ pub enum Resolution {
Fetch {
fetcher: Arc<dyn Fetcher>,
package: Package<Meta>,
name: String,
name: CompactString,
version: String,
bin_path: PathBuf,
bin_files: Vec<bins::BinFile>,

View file

@ -1,11 +1,12 @@
use std::{convert::Infallible, fmt, str::FromStr};
use compact_str::CompactString;
use itertools::Itertools;
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct CrateName {
pub name: String,
pub version: Option<String>,
pub name: CompactString,
pub version: Option<CompactString>,
}
impl fmt::Display for CrateName {
@ -26,12 +27,12 @@ impl FromStr for CrateName {
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(if let Some((name, version)) = s.split_once('@') {
CrateName {
name: name.to_string(),
version: Some(version.to_string()),
name: name.into(),
version: Some(version.into()),
}
} else {
CrateName {
name: s.to_string(),
name: s.into(),
version: None,
}
})