Skip to content

Commit

Permalink
Reduce path concat alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 committed Jan 16, 2024
1 parent 250765b commit a0d0bf5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/cache_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,13 @@ impl CacheFileInfo {
} else {
format!("{}-{}-{}", hash, self.size, self.mime_type)
};
cache_dir.join(&hash[0..2]).join(&hash[2..4]).join(filename)
let base = cache_dir.as_os_str();
let mut path = PathBuf::with_capacity(base.len() + 7 + filename.len()); // base + 2 level dir + filename length
path.push(base);
path.push(&hash[0..2]);
path.push(&hash[2..4]);
path.push(filename);
path
}

async fn get_file(&self, cache_dir: &Path) -> Option<PathBuf> {
Expand Down

0 comments on commit a0d0bf5

Please sign in to comment.