Optimize CratesToml: Use String as key

to avoid cost of deserializing (`CrateVersionSource::from_str`).

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-07-22 01:36:22 +10:00
parent 9d9a31bef3
commit 96aaca1cc6
No known key found for this signature in database
GPG key ID: 591C0B03040416D6

View file

@ -13,7 +13,7 @@ use super::CrateVersionSource;
#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CratesToml { pub struct CratesToml {
v1: BTreeMap<CrateVersionSource, BTreeSet<String>>, v1: BTreeMap<String, BTreeSet<String>>,
} }
impl CratesToml { impl CratesToml {
@ -31,7 +31,7 @@ impl CratesToml {
} }
pub fn insert(&mut self, cvs: CrateVersionSource, bins: BTreeSet<String>) { pub fn insert(&mut self, cvs: CrateVersionSource, bins: BTreeSet<String>) {
self.v1.insert(cvs, bins); self.v1.insert(cvs.to_string(), bins);
} }
pub fn write(&self) -> Result<(), CratesTomlParseError> { pub fn write(&self) -> Result<(), CratesTomlParseError> {