D6765: rustfilepatterns: shorter code for concatenating slices

valentin.gatienbaron (Valentin Gatien-Baron) phabricator at mercurial-scm.org
Wed Aug 28 07:55:16 EDT 2019


valentin.gatienbaron updated this revision to Diff 16330.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6765?vs=16328&id=16330

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6765/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6765

AFFECTED FILES
  rust/hg-core/src/filepatterns.rs

CHANGE DETAILS

diff --git a/rust/hg-core/src/filepatterns.rs b/rust/hg-core/src/filepatterns.rs
--- a/rust/hg-core/src/filepatterns.rs
+++ b/rust/hg-core/src/filepatterns.rs
@@ -158,26 +158,20 @@
             if pattern[0] == b'^' {
                 return pattern.to_owned();
             }
-            let mut res = b".*".to_vec();
-            res.extend(pattern);
-            res
+            [b".*", pattern].concat()
         }
         PatternSyntax::Path | PatternSyntax::RelPath => {
             if pattern == b"." {
                 return vec![];
             }
-            let mut pattern = escape_pattern(pattern);
-            pattern.extend(b"(?:/|$)");
-            pattern
+            [escape_pattern(pattern).as_slice(), b"(?:/|$)"].concat()
         }
         PatternSyntax::RootFiles => {
             let mut res = if pattern == b"." {
                 vec![]
             } else {
                 // Pattern is a directory name.
-                let mut as_vec: Vec<u8> = escape_pattern(pattern);
-                as_vec.push(b'/');
-                as_vec
+                [escape_pattern(pattern).as_slice(), b"/"].concat()
             };
 
             // Anything after the pattern must be a non-directory.
@@ -185,24 +179,16 @@
             res
         }
         PatternSyntax::RelGlob => {
-            let mut res: Vec<u8> = vec![];
             let glob_re = glob_to_re(pattern);
             if let Some(rest) = glob_re.drop_prefix(b"[^/]*") {
-                res.extend(b".*");
-                res.extend(rest);
+                [b".*", rest, globsuffix].concat()
             } else {
-                res.extend(b"(?:|.*/)");
-                res.extend(glob_re);
+                [b"(?:|.*/)", glob_re.as_slice(), globsuffix].concat()
             }
-            res.extend(globsuffix.iter());
-            res
         }
         PatternSyntax::Glob
         | PatternSyntax::RootGlob => {
-            let mut res: Vec<u8> = vec![];
-            res.extend(glob_to_re(pattern));
-            res.extend(globsuffix.iter());
-            res
+            [glob_to_re(pattern).as_slice(), globsuffix].concat()
         }
     }
 }



To: valentin.gatienbaron, #hg-reviewers, Alphare, kevincox
Cc: durin42, kevincox, mercurial-devel


More information about the Mercurial-devel mailing list