perf(runtime-bundle): reuse the normalized destination buffer

This commit is contained in:
Tunglies
2026-12-03 21:39:25 +08:00
parent 1c4bf7c223
commit 675933c5f0
+10 -2
View File
@@ -445,7 +445,7 @@ fn destination_below_root(config_root: &Path, path: &Path) -> Result<String> {
}
fn normalized_destination(relative: &Path) -> Result<String> {
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<String> {
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)]