changeset 42865:69195b6f8f97

rustfilepatterns: shorter code for concatenating slices Differential Revision: https://phab.mercurial-scm.org/D6765
author Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
date Sun, 25 Aug 2019 23:40:22 -0400
parents 72890d8f9860
children 141bb77b606b
files rust/hg-core/src/filepatterns.rs
diffstat 1 files changed, 6 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/filepatterns.rs	Sun Aug 25 22:53:42 2019 -0400
+++ b/rust/hg-core/src/filepatterns.rs	Sun Aug 25 23:40:22 2019 -0400
@@ -159,26 +159,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.
@@ -186,23 +180,15 @@
             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()
         }
     }
 }