From 357573274c70096841aedee4e664ec8e3fbed926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Thu, 10 Jul 2025 12:33:22 +0200 Subject: [PATCH 1/2] Improves performances --- src/fs.rs | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/fs.rs b/src/fs.rs index 41c10a5..3b45bd0 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -210,7 +210,7 @@ fn vpath(p: &Path) -> std::io::Result { segment_it.next(); } - let mut base_items: Vec<&str> = Vec::new(); + let mut base_items: Vec<&str> = Vec::with_capacity(10); let mut virtual_items: Option> = None; let mut internal_items: Option> = None; @@ -248,13 +248,13 @@ fn vpath(p: &Path) -> std::io::Result { } virtual_items = Some(acc_segments); - internal_items = Some(vec![]); + internal_items = Some(Vec::with_capacity(10)); continue; } if segment.len() > 4 && segment.ends_with(".zip") { - zip_items = Some(vec![]); + zip_items = Some(Vec::with_capacity(10)); } if let Some(virtual_segments) = &mut virtual_items { @@ -268,14 +268,7 @@ fn vpath(p: &Path) -> std::io::Result { } } - let mut base_path = base_items.join("/"); - - // Don't forget to add back the leading slash we removed earlier - if normalized_relative_path != normalized_path { - base_path.insert(0, '/'); - } - - let virtual_info = match (virtual_items, internal_items) { + let virtual_segments = match (virtual_items, internal_items) { (Some(virtual_segments), Some(internal_segments)) => { Some((virtual_segments.join("/"), internal_segments.join("/"))) } @@ -284,20 +277,37 @@ fn vpath(p: &Path) -> std::io::Result { }; if let Some(zip_segments) = zip_items { + let mut base_path = base_items.join("/"); + + // Don't forget to add back the leading slash we removed earlier + if normalized_relative_path != normalized_path { + base_path.insert(0, '/'); + } + if !zip_segments.is_empty() { return Ok(VPath::Zip(ZipInfo { base_path, - virtual_segments: virtual_info, + virtual_segments, zip_path: zip_segments.join("/"), })); } } - if let Some(virtual_info) = virtual_info { - return Ok(VPath::Virtual(VirtualInfo { base_path, virtual_segments: virtual_info })); + if let Some(virtual_segments) = virtual_segments { + let mut base_path = base_items.join("/"); + + // Don't forget to add back the leading slash we removed earlier + if normalized_relative_path != normalized_path { + base_path.insert(0, '/'); + } + + return Ok(VPath::Virtual(VirtualInfo { + base_path, + virtual_segments, + })); } - Ok(VPath::Native(PathBuf::from(base_path))) + Ok(VPath::Native(PathBuf::from(normalized_path))) } #[cfg(test)] From f0b92df2edf1dd1d5fb633229660aa67ec9ac848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Thu, 10 Jul 2025 12:44:41 +0200 Subject: [PATCH 2/2] fmt --- .github/workflows/bench.yml | 2 ++ src/fs.rs | 5 +---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index 935f28d..6ebdd1a 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -6,6 +6,8 @@ on: jobs: bench: runs-on: ubuntu-latest + permissions: + pull-requests: write steps: - uses: taiki-e/checkout-action@v1 diff --git a/src/fs.rs b/src/fs.rs index 3b45bd0..1df459c 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -301,10 +301,7 @@ fn vpath(p: &Path) -> std::io::Result { base_path.insert(0, '/'); } - return Ok(VPath::Virtual(VirtualInfo { - base_path, - virtual_segments, - })); + return Ok(VPath::Virtual(VirtualInfo { base_path, virtual_segments })); } Ok(VPath::Native(PathBuf::from(normalized_path)))