Skip to content

Commit

Permalink
Simplify full directory index gen
Browse files Browse the repository at this point in the history
  • Loading branch information
trumank committed May 31, 2024
1 parent 2bd2843 commit b13c073
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions repak/src/pak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ fn generate_full_directory_index<W: Write>(
entries: &BTreeMap<String, super::entry::Entry>,
offsets: &Vec<u32>,
) -> Result<(), super::Error> {
let mut fdi = BTreeMap::new();
let mut fdi: BTreeMap<&str, BTreeMap<&str, u32>> = Default::default();
for (path, offset) in entries.keys().zip(offsets) {
let mut p = path.as_str();
while let Some((parent, _)) = split_path_child(p) {
Expand All @@ -653,15 +653,7 @@ fn generate_full_directory_index<W: Write>(

let (directory, filename) = split_path_child(path).expect("none root path");

fdi.entry(directory)
.and_modify(|d: &mut BTreeMap<&str, u32>| {
d.insert(filename, *offset);
})
.or_insert_with(|| {
let mut files_and_offsets = BTreeMap::new();
files_and_offsets.insert(filename, *offset);
files_and_offsets
});
fdi.entry(directory).or_default().insert(filename, *offset);
}

writer.write_u32::<LE>(fdi.len() as u32)?;
Expand Down

0 comments on commit b13c073

Please sign in to comment.