D6769: another way of implementing the parent

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


valentin.gatienbaron created this revision.
Herald added subscribers: mercurial-devel, kevincox, durin42.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  I would drop this or fold it into the parent depending on reviewers' opinion.
  
  The problem is that byte literals can converted to slices implicitely,
  and concat can work on slices and other things, and it's too much for
  the typer to try to do both at the time. Providing a monomorphic version
  of the concat method avoids having to write &byteliteral[..].

REPOSITORY
  rHG Mercurial

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

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

CHANGE DETAILS

diff --git a/rust/hg-core/src/utils.rs b/rust/hg-core/src/utils.rs
--- a/rust/hg-core/src/utils.rs
+++ b/rust/hg-core/src/utils.rs
@@ -37,6 +37,10 @@
     }
 }
 
+pub fn concat(slices: &[&[u8]]) -> Vec<u8> {
+    slices.concat()
+}
+
 pub trait SliceExt {
     fn trim_end(&self) -> &Self;
     fn trim_start(&self) -> &Self;
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
@@ -8,7 +8,7 @@
 //! Handling of Mercurial-specific patterns.
 
 use crate::{
-    utils::{files::get_path_from_bytes, SliceExt},
+    utils::{concat, files::get_path_from_bytes, SliceExt},
     LineNumber, PatternError, PatternFileError,
 };
 use lazy_static::lazy_static;
@@ -158,20 +158,20 @@
             if pattern[0] == b'^' {
                 return pattern.to_owned();
             }
-            [&b".*"[..], pattern].concat()
+            concat(&[b".*", pattern])
         }
         PatternSyntax::Path | PatternSyntax::RelPath => {
             if pattern == b"." {
                 return vec![];
             }
-            [&escape_pattern(pattern), &b"(?:/|$)"[..]].concat()
+            concat(&[&escape_pattern(pattern), b"(?:/|$)"])
         }
         PatternSyntax::RootFiles => {
             let mut res = if pattern == b"." {
                 vec![]
             } else {
                 // Pattern is a directory name.
-                [&escape_pattern(pattern), &b"/"[..]].concat()
+                concat(&[&escape_pattern(pattern), b"/"])
             };
 
             // Anything after the pattern must be a non-directory.
@@ -181,14 +181,14 @@
         PatternSyntax::RelGlob => {
             let glob_re = glob_to_re(pattern);
             if let Some(rest) = glob_re.drop_prefix(b"[^/]*") {
-                [&b".*"[..], rest, globsuffix].concat()
+                concat(&[b".*", rest, globsuffix])
             } else {
-                [&b"(?:|.*/)"[..], &glob_re, globsuffix].concat()
+                concat(&[b"(?:|.*/)", &glob_re, globsuffix])
             }
         }
         PatternSyntax::Glob
         | PatternSyntax::RootGlob => {
-            [&glob_to_re(pattern), globsuffix].concat()
+            concat(&[&glob_to_re(pattern), globsuffix])
         }
     }
 }



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


More information about the Mercurial-devel mailing list