[Updated] D11721: rhg: more efficient `HgPath::join`

aalekseyev (Arseniy Alekseyev) phabricator at mercurial-scm.org
Tue Nov 9 15:03:27 UTC 2021


Closed by commit rHG6d69e83e6b6e: rhg: more efficient `HgPath::join` (authored by aalekseyev).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D11721?vs=30991&id=31043

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

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

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

CHANGE DETAILS

diff --git a/rust/hg-core/src/utils/hg_path.rs b/rust/hg-core/src/utils/hg_path.rs
--- a/rust/hg-core/src/utils/hg_path.rs
+++ b/rust/hg-core/src/utils/hg_path.rs
@@ -220,13 +220,11 @@
             ),
         }
     }
-    pub fn join<T: ?Sized + AsRef<Self>>(&self, other: &T) -> HgPathBuf {
-        let mut inner = self.inner.to_owned();
-        if !inner.is_empty() && inner.last() != Some(&b'/') {
-            inner.push(b'/');
-        }
-        inner.extend(other.as_ref().bytes());
-        HgPathBuf::from_bytes(&inner)
+
+    pub fn join(&self, path: &HgPath) -> HgPathBuf {
+        let mut buf = self.to_owned();
+        buf.push(path);
+        buf
     }
 
     pub fn components(&self) -> impl Iterator<Item = &HgPath> {
@@ -405,7 +403,15 @@
     pub fn new() -> Self {
         Default::default()
     }
-    pub fn push(&mut self, byte: u8) {
+
+    pub fn push<T: ?Sized + AsRef<HgPath>>(&mut self, other: &T) -> () {
+        if !self.inner.is_empty() && self.inner.last() != Some(&b'/') {
+            self.inner.push(b'/');
+        }
+        self.inner.extend(other.as_ref().bytes())
+    }
+
+    pub fn push_byte(&mut self, byte: u8) {
         self.inner.push(byte);
     }
     pub fn from_bytes(s: &[u8]) -> HgPathBuf {
diff --git a/rust/hg-core/src/matchers.rs b/rust/hg-core/src/matchers.rs
--- a/rust/hg-core/src/matchers.rs
+++ b/rust/hg-core/src/matchers.rs
@@ -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"." {
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
@@ -536,7 +536,7 @@
         Ok(Self {
             prefix: path_to_hg_path_buf(prefix).and_then(|mut p| {
                 if !p.is_empty() {
-                    p.push(b'/');
+                    p.push_byte(b'/');
                 }
                 Ok(p)
             })?,



To: aalekseyev, #hg-reviewers, Alphare, pulkit
Cc: Alphare, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20211109/b05c9d8e/attachment-0001.html>


More information about the Mercurial-patches mailing list