Optimize drivers::crates_io::Vfs: Use BTreeMap (#325) instead of HashMap.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-08-27 20:18:25 +10:00 committed by GitHub
parent 16b16c482c
commit 7f9ad613a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 8 deletions

View file

@ -1,5 +1,5 @@
use std::{ use std::{
collections::{hash_map::HashMap, hash_set::HashSet}, collections::{hash_set::HashSet, BTreeMap},
io, io,
path::Path, path::Path,
}; };
@ -10,14 +10,10 @@ use normalize_path::NormalizePath;
/// This type stores the filesystem structure for the crate tarball /// This type stores the filesystem structure for the crate tarball
/// extracted in memory and can be passed to /// extracted in memory and can be passed to
/// `cargo_toml::Manifest::complete_from_abstract_filesystem`. /// `cargo_toml::Manifest::complete_from_abstract_filesystem`.
#[derive(Debug)] #[derive(Debug, Default)]
pub(super) struct Vfs(HashMap<Box<Path>, HashSet<Box<str>>>); pub(super) struct Vfs(BTreeMap<Box<Path>, HashSet<Box<str>>>);
impl Vfs { impl Vfs {
pub(super) fn new() -> Self {
Self(HashMap::with_capacity(16))
}
/// * `path` - must be canonical, must not be empty. /// * `path` - must be canonical, must not be empty.
pub(super) fn add_path(&mut self, mut path: &Path) { pub(super) fn add_path(&mut self, mut path: &Path) {
while let Some(parent) = path.parent() { while let Some(parent) = path.parent() {

View file

@ -29,7 +29,7 @@ impl ManifestVisitor {
// Cargo.toml is quite large usually. // Cargo.toml is quite large usually.
cargo_toml_content: Vec::with_capacity(2000), cargo_toml_content: Vec::with_capacity(2000),
manifest_dir_path, manifest_dir_path,
vfs: Vfs::new(), vfs: Vfs::default(),
} }
} }
} }