[Updated] D10199: rust: Preallocate the returned `Vec` in `utils::files::relativize_path`
SimonSapin
phabricator at mercurial-scm.org
Wed Mar 17 14:42:37 UTC 2021
Closed by commit rHGc94fa884240b: rust: Preallocate the returned `Vec` in `utils::files::relativize_path` (authored by SimonSapin).
This revision was automatically updated to reflect the committed changes.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D10199?vs=26313&id=26483
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D10199/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D10199
AFFECTED FILES
rust/hg-core/src/utils/files.rs
CHANGE DETAILS
diff --git a/rust/hg-core/src/utils/files.rs b/rust/hg-core/src/utils/files.rs
--- a/rust/hg-core/src/utils/files.rs
+++ b/rust/hg-core/src/utils/files.rs
@@ -290,7 +290,13 @@
if cwd.as_ref().is_empty() {
Cow::Borrowed(path.as_bytes())
} else {
- let mut res: Vec<u8> = Vec::new();
+ // This is not all accurate as to how large `res` will actually be, but
+ // profiling `rhg files` on a large-ish repo shows it’s better than
+ // starting from a zero-capacity `Vec` and letting `extend` reallocate
+ // repeatedly.
+ let guesstimate = path.as_bytes().len();
+
+ let mut res: Vec<u8> = Vec::with_capacity(guesstimate);
let mut path_iter = path.as_bytes().split(|b| *b == b'/').peekable();
let mut cwd_iter =
cwd.as_ref().as_bytes().split(|b| *b == b'/').peekable();
To: SimonSapin, #hg-reviewers, Alphare, pulkit
Cc: Alphare, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20210317/b44dd8a0/attachment-0002.html>
More information about the Mercurial-patches
mailing list