comparison 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
comparison
equal deleted inserted replaced
48310:229f5ee1a08a 48311:6d69e83e6b6e
389 let IgnorePattern { 389 let IgnorePattern {
390 syntax, pattern, .. 390 syntax, pattern, ..
391 } = ignore_pattern; 391 } = ignore_pattern;
392 match syntax { 392 match syntax {
393 PatternSyntax::RootGlob | PatternSyntax::Glob => { 393 PatternSyntax::RootGlob | PatternSyntax::Glob => {
394 let mut root = vec![]; 394 let mut root = HgPathBuf::new();
395
396 for p in pattern.split(|c| *c == b'/') { 395 for p in pattern.split(|c| *c == b'/') {
397 if p.iter().any(|c| match *c { 396 if p.iter().any(|c| match *c {
398 b'[' | b'{' | b'*' | b'?' => true, 397 b'[' | b'{' | b'*' | b'?' => true,
399 _ => false, 398 _ => false,
400 }) { 399 }) {
401 break; 400 break;
402 } 401 }
403 root.push(HgPathBuf::from_bytes(p)); 402 root.push(HgPathBuf::from_bytes(p).as_ref());
404 } 403 }
405 let buf = 404 roots.push(root);
406 root.iter().fold(HgPathBuf::new(), |acc, r| acc.join(r));
407 roots.push(buf);
408 } 405 }
409 PatternSyntax::Path | PatternSyntax::RelPath => { 406 PatternSyntax::Path | PatternSyntax::RelPath => {
410 let pat = HgPath::new(if pattern == b"." { 407 let pat = HgPath::new(if pattern == b"." {
411 &[] as &[u8] 408 &[] as &[u8]
412 } else { 409 } else {