Skip to content

Commit 790b34f

Browse files
authored
perf: use fxhash in zip data structures (#28)
1 parent 6effdac commit 790b34f

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/zip.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
use std::{
2+
error::Error,
3+
io::{Cursor, Read},
4+
};
5+
16
use byteorder::{LittleEndian, ReadBytesExt};
2-
use std::collections::{HashMap, HashSet};
3-
use std::error::Error;
4-
use std::io::Cursor;
5-
use std::io::Read;
7+
use rustc_hash::{FxHashMap, FxHashSet};
68

79
use crate::fs::FileType;
810
use crate::util;
@@ -26,8 +28,8 @@ where
2628
T: AsRef<[u8]>,
2729
{
2830
storage: T,
29-
pub files: HashMap<String, Entry>,
30-
pub dirs: HashSet<String>,
31+
pub files: FxHashMap<String, Entry>,
32+
pub dirs: FxHashSet<String>,
3133
}
3234

3335
impl<T> Zip<T>
@@ -103,8 +105,8 @@ fn make_io_utf8_error() -> std::io::Error {
103105
std::io::Error::new(std::io::ErrorKind::InvalidData, "File did not contain valid UTF-8")
104106
}
105107

106-
pub fn list_zip_entries(data: &[u8]) -> Result<HashMap<String, Option<Entry>>, Box<dyn Error>> {
107-
let mut zip_entries = HashMap::new();
108+
pub fn list_zip_entries(data: &[u8]) -> Result<FxHashMap<String, Option<Entry>>, Box<dyn Error>> {
109+
let mut zip_entries = FxHashMap::default();
108110
let mut cursor = Cursor::new(data);
109111

110112
let central_directory_offset = find_central_directory_offset(&mut cursor)?;

0 commit comments

Comments
 (0)