From 626a5af3a496bd44d313deab00fe141d4fbe58ec Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 10 Mar 2024 14:39:29 +0100 Subject: [PATCH] Use HashMap instead of BTreeMap This reduces the file size from 87KiB to 79KiB. --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/initfs.rs | 9 ++++++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e92a7c6d7a..885b28f1f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,6 +18,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" name = "bootstrap" version = "0.0.0" dependencies = [ + "hashbrown", "linked_list_allocator", "redox-exec", "redox-initfs", @@ -35,6 +36,12 @@ dependencies = [ "scroll", ] +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + [[package]] name = "linked_list_allocator" version = "0.10.5" diff --git a/Cargo.toml b/Cargo.toml index 2ae5bb45a0..feb816d5e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ name = "bootstrap" crate-type = ["staticlib"] [dependencies] +hashbrown = { version = "0.14", default-features = false, features = ["inline-more"] } linked_list_allocator = "0.10" redox-initfs = { git = "https://gitlab.redox-os.org/redox-os/redox-initfs.git", features = ["kernel"], default-features = false } redox-exec = { git = "https://gitlab.redox-os.org/redox-os/relibc.git" } diff --git a/src/initfs.rs b/src/initfs.rs index 7303134594..e4ed8d4951 100644 --- a/src/initfs.rs +++ b/src/initfs.rs @@ -1,9 +1,11 @@ use core::convert::TryFrom; +#[allow(deprecated)] +use core::hash::{BuildHasherDefault, SipHasher}; use core::str; -use alloc::collections::BTreeMap; use alloc::string::String; +use hashbrown::HashMap; use redox_initfs::{InitFs, InodeStruct, Inode, InodeDir, InodeKind, types::Timespec}; use syscall::data::{Packet, Stat}; @@ -19,14 +21,15 @@ struct Handle { filename: String, } pub struct InitFsScheme { - handles: BTreeMap, + #[allow(deprecated)] + handles: HashMap>, next_id: usize, fs: InitFs<'static>, } impl InitFsScheme { pub fn new(bytes: &'static [u8]) -> Self { Self { - handles: BTreeMap::new(), + handles: HashMap::default(), next_id: 0, fs: InitFs::new(bytes).expect("failed to parse initfs"), }