Mercurial > public > mercurial-scm > hg
diff rust/hg-core/src/matchers.rs @ 48311:6d69e83e6b6e
rhg: more efficient `HgPath::join`
This commit makes `HgPath::join` slightly more efficient
by avoiding one copy.
It also avoids a particularly inefficient (quadratic) use of
`HgPath::join` by using a new mutating function `HgPathBuf::push` instead.
The name for `HgPathBuf::push` is chosen by analogy to `PathBuf::push`.
Differential Revision: https://phab.mercurial-scm.org/D11721
author | Arseniy Alekseyev <aalekseyev@janestreet.com> |
---|---|
date | Tue, 26 Oct 2021 19:47:30 +0100 |
parents | 0ef8231e413f |
children | 2009e3c64a53 |
line wrap: on
line diff
--- a/rust/hg-core/src/matchers.rs Tue Nov 09 15:25:38 2021 +0100 +++ b/rust/hg-core/src/matchers.rs Tue Oct 26 19:47:30 2021 +0100 @@ -391,8 +391,7 @@ } = ignore_pattern; match syntax { PatternSyntax::RootGlob | PatternSyntax::Glob => { - let mut root = vec![]; - + let mut root = HgPathBuf::new(); for p in pattern.split(|c| *c == b'/') { if p.iter().any(|c| match *c { b'[' | b'{' | b'*' | b'?' => true, @@ -400,11 +399,9 @@ }) { break; } - root.push(HgPathBuf::from_bytes(p)); + root.push(HgPathBuf::from_bytes(p).as_ref()); } - let buf = - root.iter().fold(HgPathBuf::new(), |acc, r| acc.join(r)); - roots.push(buf); + roots.push(root); } PatternSyntax::Path | PatternSyntax::RelPath => { let pat = HgPath::new(if pattern == b"." {