mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-20 20:48:43 +00:00
Optimize CratesToml::collect_into_crates_versions
(#589)
Avoid calling `CrateVersionSource::from_str` which parses the source and allocates `Url`. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
23a5937aff
commit
ec026c1711
1 changed files with 8 additions and 5 deletions
|
@ -13,7 +13,6 @@ use std::{
|
||||||
io::{self, Seek},
|
io::{self, Seek},
|
||||||
iter::IntoIterator,
|
iter::IntoIterator,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
str::FromStr,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use compact_str::CompactString;
|
use compact_str::CompactString;
|
||||||
|
@ -131,12 +130,16 @@ impl CratesToml {
|
||||||
pub fn collect_into_crates_versions(
|
pub fn collect_into_crates_versions(
|
||||||
self,
|
self,
|
||||||
) -> Result<BTreeMap<CompactString, Version>, CratesTomlParseError> {
|
) -> Result<BTreeMap<CompactString, Version>, CratesTomlParseError> {
|
||||||
|
fn parse_name_ver(s: &str) -> Result<(CompactString, Version), CvsParseError> {
|
||||||
|
match s.splitn(3, ' ').collect::<Vec<_>>()[..] {
|
||||||
|
[name, version, _source] => Ok((CompactString::new(name), version.parse()?)),
|
||||||
|
_ => Err(CvsParseError::BadFormat),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.v1
|
self.v1
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(s, _bins)| {
|
.map(|(s, _bins)| parse_name_ver(&s).map_err(CratesTomlParseError::from))
|
||||||
let cvs = CrateVersionSource::from_str(&s)?;
|
|
||||||
Ok((cvs.name, cvs.version))
|
|
||||||
})
|
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue