From 7f9ad613a813f1e989ef87aa116b93601ece66c5 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sat, 27 Aug 2022 20:18:25 +1000 Subject: [PATCH] Optimize `drivers::crates_io::Vfs`: Use `BTreeMap` (#325) instead of `HashMap`. Signed-off-by: Jiahao XU --- crates/lib/src/drivers/crates_io/vfs.rs | 10 +++------- crates/lib/src/drivers/crates_io/visitor.rs | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/crates/lib/src/drivers/crates_io/vfs.rs b/crates/lib/src/drivers/crates_io/vfs.rs index 3cd53627..d0ae6a6b 100644 --- a/crates/lib/src/drivers/crates_io/vfs.rs +++ b/crates/lib/src/drivers/crates_io/vfs.rs @@ -1,5 +1,5 @@ use std::{ - collections::{hash_map::HashMap, hash_set::HashSet}, + collections::{hash_set::HashSet, BTreeMap}, io, path::Path, }; @@ -10,14 +10,10 @@ use normalize_path::NormalizePath; /// This type stores the filesystem structure for the crate tarball /// extracted in memory and can be passed to /// `cargo_toml::Manifest::complete_from_abstract_filesystem`. -#[derive(Debug)] -pub(super) struct Vfs(HashMap, HashSet>>); +#[derive(Debug, Default)] +pub(super) struct Vfs(BTreeMap, HashSet>>); impl Vfs { - pub(super) fn new() -> Self { - Self(HashMap::with_capacity(16)) - } - /// * `path` - must be canonical, must not be empty. pub(super) fn add_path(&mut self, mut path: &Path) { while let Some(parent) = path.parent() { diff --git a/crates/lib/src/drivers/crates_io/visitor.rs b/crates/lib/src/drivers/crates_io/visitor.rs index 5efc8012..01a71d39 100644 --- a/crates/lib/src/drivers/crates_io/visitor.rs +++ b/crates/lib/src/drivers/crates_io/visitor.rs @@ -29,7 +29,7 @@ impl ManifestVisitor { // Cargo.toml is quite large usually. cargo_toml_content: Vec::with_capacity(2000), manifest_dir_path, - vfs: Vfs::new(), + vfs: Vfs::default(), } } }