mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-12 23:23:20 +00:00
repo_path: avoid repeated copying of PathBuf
in to_fs_path()
I've noticed `WorkspaceCommandHelper::format_file_path()` appear in profiles a few times. A big part of that is spent in `RepoPath::to_fs_path()`. I think I had been thinking that `PathBuf::join()` takes `self` by value and mutates it, but it turns out it creates a new instance. So our `result = result.join(...)` in a loop was copying the `PathBuf` over and over. This fixes that and also reserves the expected size. That speeds up `jj files --ignore-working-copy -r v6.0` in the Linux repo from 546.0 s to 509.3 s (6.7%).
This commit is contained in:
parent
2e8b824da7
commit
86206e83a4
1 changed files with 4 additions and 4 deletions
|
@ -138,10 +138,10 @@ impl RepoPath {
|
|||
}
|
||||
|
||||
pub fn to_fs_path(&self, base: &Path) -> PathBuf {
|
||||
let mut result = base.to_owned();
|
||||
for dir in &self.components {
|
||||
result = result.join(&dir.value);
|
||||
}
|
||||
let repo_path_len: usize = self.components.iter().map(|x| x.as_str().len() + 1).sum();
|
||||
let mut result = PathBuf::with_capacity(base.as_os_str().len() + repo_path_len);
|
||||
result.push(base);
|
||||
result.extend(self.components.iter().map(|dir| &dir.value));
|
||||
result
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue