mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-04 05:00:05 +08:00
perf(runtime-bundle): reuse the normalized destination buffer
This commit is contained in:
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user