changeset 47477:eb416759af7e

dirstate: Removed unused instances of `DirsMultiset` … in Rust-backed dirstatemap. The Python class `dirstatemap` had cached properties `_dirs` and `_alldirs` that were not used for `hastrackeddir` and `hasdir` since they were redundant with corresponding fields for the Rust `DirstateMap` struct. `dirfoldmap` is modified to reuse instead the directory iterator introduced in 3b9914b28133c0918186b6e8b9e4f1916e21338d. Differential Revision: https://phab.mercurial-scm.org/D10921
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 28 Jun 2021 15:52:10 +0200
parents f23eafb036af
children ca8121d26732
files contrib/perf.py mercurial/dirstate.py rust/hg-core/src/dirstate_tree/dirstate_map.rs rust/hg-core/src/dirstate_tree/dispatch.rs rust/hg-cpython/src/dirstate/dirstate_map.rs rust/hg-cpython/src/dirstate/dispatch.rs
diffstat 6 files changed, 16 insertions(+), 83 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/perf.py	Mon Jun 28 15:41:50 2021 +0200
+++ b/contrib/perf.py	Mon Jun 28 15:52:10 2021 +0200
@@ -1147,7 +1147,10 @@
 
     def d():
         dirstate.hasdir(b'a')
-        del dirstate._map._dirs
+        try:
+            del dirstate._map._dirs
+        except AttributeError:
+            pass
 
     timer(d)
     fm.end()
@@ -1225,7 +1228,10 @@
     repo.dirstate.hasdir(b"a")
 
     def setup():
-        del repo.dirstate._map._dirs
+        try:
+            del repo.dirstate._map._dirs
+        except AttributeError:
+            pass
 
     def d():
         repo.dirstate.hasdir(b"a")
@@ -1268,7 +1274,10 @@
 
     def setup():
         del dirstate._map.dirfoldmap
-        del dirstate._map._dirs
+        try:
+            del dirstate._map._dirs
+        except AttributeError:
+            pass
 
     def d():
         dirstate._map.dirfoldmap.get(b'a')
--- a/mercurial/dirstate.py	Mon Jun 28 15:41:50 2021 +0200
+++ b/mercurial/dirstate.py	Mon Jun 28 15:52:10 2021 +0200
@@ -1951,22 +1951,12 @@
             return self._rustmap.filefoldmapasdict()
 
         def hastrackeddir(self, d):
-            self._dirs  # Trigger Python's propertycache
             return self._rustmap.hastrackeddir(d)
 
         def hasdir(self, d):
-            self._dirs  # Trigger Python's propertycache
             return self._rustmap.hasdir(d)
 
         @propertycache
-        def _dirs(self):
-            return self._rustmap.getdirs()
-
-        @propertycache
-        def _alldirs(self):
-            return self._rustmap.getalldirs()
-
-        @propertycache
         def identity(self):
             self._rustmap
             return self.identity
@@ -1988,6 +1978,6 @@
         def dirfoldmap(self):
             f = {}
             normcase = util.normcase
-            for name in self._dirs:
+            for name, _pseudo_entry in self.directories():
                 f[normcase(name)] = name
             return f
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs	Mon Jun 28 15:41:50 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs	Mon Jun 28 15:52:10 2021 +0200
@@ -977,18 +977,6 @@
         on_disk::write(self, parents)
     }
 
-    fn set_all_dirs(&mut self) -> Result<(), DirstateError> {
-        // Do nothing, this `DirstateMap` does not a separate `all_dirs` that
-        // needs to be recomputed
-        Ok(())
-    }
-
-    fn set_dirs(&mut self) -> Result<(), DirstateError> {
-        // Do nothing, this `DirstateMap` does not a separate `dirs` that needs
-        // to be recomputed
-        Ok(())
-    }
-
     fn status<'a>(
         &'a mut self,
         matcher: &'a (dyn Matcher + Sync),
--- a/rust/hg-core/src/dirstate_tree/dispatch.rs	Mon Jun 28 15:41:50 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/dispatch.rs	Mon Jun 28 15:52:10 2021 +0200
@@ -95,10 +95,6 @@
         now: Timestamp,
     ) -> Result<Vec<u8>, DirstateError>;
 
-    fn set_all_dirs(&mut self) -> Result<(), DirstateError>;
-
-    fn set_dirs(&mut self) -> Result<(), DirstateError>;
-
     fn status<'a>(
         &'a mut self,
         matcher: &'a (dyn Matcher + Sync),
@@ -281,14 +277,6 @@
         )
     }
 
-    fn set_all_dirs(&mut self) -> Result<(), DirstateError> {
-        self.set_all_dirs()
-    }
-
-    fn set_dirs(&mut self) -> Result<(), DirstateError> {
-        self.set_dirs()
-    }
-
     fn status<'a>(
         &'a mut self,
         matcher: &'a (dyn Matcher + Sync),
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs	Mon Jun 28 15:41:50 2021 +0200
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs	Mon Jun 28 15:52:10 2021 +0200
@@ -19,11 +19,11 @@
 
 use crate::{
     dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator},
+    dirstate::make_dirstate_tuple,
     dirstate::non_normal_entries::{
         NonNormalEntries, NonNormalEntriesIterator,
     },
     dirstate::owning::OwningDirstateMap,
-    dirstate::{dirs_multiset::Dirs, make_dirstate_tuple},
     parsers::dirstate_parents_to_pytuple,
 };
 use hg::{
@@ -34,8 +34,8 @@
     revlog::Node,
     utils::files::normalize_case,
     utils::hg_path::{HgPath, HgPathBuf},
-    DirsMultiset, DirstateEntry, DirstateError,
-    DirstateMap as RustDirstateMap, DirstateParents, EntryState, StateMapIter,
+    DirstateEntry, DirstateError, DirstateMap as RustDirstateMap,
+    DirstateParents, EntryState, StateMapIter,
 };
 
 // TODO
@@ -391,40 +391,6 @@
         )
     }
 
-    def getdirs(&self) -> PyResult<Dirs> {
-        // TODO don't copy, share the reference
-        self.inner(py).borrow_mut().set_dirs()
-            .map_err(|e| {
-                PyErr::new::<exc::ValueError, _>(py, e.to_string())
-            })?;
-        Dirs::from_inner(
-            py,
-            DirsMultiset::from_dirstate(
-                self.inner(py).borrow().iter(),
-                Some(EntryState::Removed),
-            )
-            .map_err(|e| {
-                PyErr::new::<exc::ValueError, _>(py, e.to_string())
-            })?,
-        )
-    }
-    def getalldirs(&self) -> PyResult<Dirs> {
-        // TODO don't copy, share the reference
-        self.inner(py).borrow_mut().set_all_dirs()
-            .map_err(|e| {
-                PyErr::new::<exc::ValueError, _>(py, e.to_string())
-            })?;
-        Dirs::from_inner(
-            py,
-            DirsMultiset::from_dirstate(
-                self.inner(py).borrow().iter(),
-                None,
-            ).map_err(|e| {
-                PyErr::new::<exc::ValueError, _>(py, e.to_string())
-            })?,
-        )
-    }
-
     // TODO all copymap* methods, see docstring above
     def copymapcopy(&self) -> PyResult<PyDict> {
         let dict = PyDict::new(py);
--- a/rust/hg-cpython/src/dirstate/dispatch.rs	Mon Jun 28 15:41:50 2021 +0200
+++ b/rust/hg-cpython/src/dirstate/dispatch.rs	Mon Jun 28 15:52:10 2021 +0200
@@ -128,14 +128,6 @@
         self.get_mut().pack_v2(parents, now)
     }
 
-    fn set_all_dirs(&mut self) -> Result<(), DirstateError> {
-        self.get_mut().set_all_dirs()
-    }
-
-    fn set_dirs(&mut self) -> Result<(), DirstateError> {
-        self.get_mut().set_dirs()
-    }
-
     fn status<'a>(
         &'a mut self,
         matcher: &'a (dyn Matcher + Sync),