From 675933c5f08aef83a68a6ff8b2869209de338952 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Thu, 3 Dec 2026 21:39:25 +0800 Subject: [PATCH] perf(runtime-bundle): reuse the normalized destination buffer --- crates/clash-verge-runtime-bundle/src/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/clash-verge-runtime-bundle/src/lib.rs b/crates/clash-verge-runtime-bundle/src/lib.rs index 728de705f..16aee2f8d 100644 --- a/crates/clash-verge-runtime-bundle/src/lib.rs +++ b/crates/clash-verge-runtime-bundle/src/lib.rs @@ -445,7 +445,7 @@ fn destination_below_root(config_root: &Path, path: &Path) -> Result { } fn normalized_destination(relative: &Path) -> Result { - let mut destination = PathBuf::new(); + let mut destination = PathBuf::with_capacity(relative.as_os_str().len()); for component in relative.components() { match component { Component::Normal(component) => destination.push(component), @@ -456,7 +456,15 @@ fn normalized_destination(relative: &Path) -> Result { if destination.as_os_str().is_empty() { return Err(RuntimeBundleError::EmptyDestination); } - Ok(destination.to_string_lossy().replace('\\', "/")) + let destination = destination + .into_os_string() + .into_string() + .unwrap_or_else(|path| path.to_string_lossy().into_owned()); + if destination.contains('\\') { + Ok(destination.replace('\\', "/")) + } else { + Ok(destination) + } } #[cfg(test)]