Patchwork D9112: changing-files: cache the various property

login
register
mail settings
Submitter phabricator
Date Sept. 28, 2020, 4:32 p.m.
Message ID <differential-rev-PHID-DREV-4dpmhwtzts4ku7r5with-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47327/
State Superseded
Headers show

Comments

phabricator - Sept. 28, 2020, 4:32 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  We are going to start using them more having some basic caching would be good.
  The focus is not about performance yet, however avoid some easy N² trap seems
  reasonable.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/metadata.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/metadata.py b/mercurial/metadata.py
--- a/mercurial/metadata.py
+++ b/mercurial/metadata.py
@@ -70,7 +70,7 @@ 
             and self.copied_from_p2 == other.copied_from_p2
         )
 
-    @property
+    @util.propertycache
     def added(self):
         """files actively added in the changeset
 
@@ -84,6 +84,8 @@ 
         return frozenset(self._added)
 
     def mark_added(self, filename):
+        if 'added' in vars(self):
+            del self.added
         self._added.add(filename)
         self.mark_touched(filename)
 
@@ -91,7 +93,7 @@ 
         for f in filenames:
             self.mark_added(f)
 
-    @property
+    @util.propertycache
     def merged(self):
         """files actively merged during a merge
 
@@ -102,6 +104,8 @@ 
         return frozenset(self._merged)
 
     def mark_merged(self, filename):
+        if 'merged' in vars(self):
+            del self.merged
         self._merged.add(filename)
         self.mark_touched(filename)
 
@@ -109,7 +113,7 @@ 
         for f in filenames:
             self.mark_merged(f)
 
-    @property
+    @util.propertycache
     def removed(self):
         """files actively removed by the changeset
 
@@ -146,6 +150,8 @@ 
         return frozenset(self._removed)
 
     def mark_removed(self, filename):
+        if 'removed' in vars(self):
+            del self.removed
         self._removed.add(filename)
         self.mark_touched(filename)
 
@@ -153,34 +159,40 @@ 
         for f in filenames:
             self.mark_removed(f)
 
-    @property
+    @util.propertycache
     def touched(self):
         """files either actively modified, added or removed"""
         return frozenset(self._touched)
 
     def mark_touched(self, filename):
+        if 'touched' in vars(self):
+            del self.touched
         self._touched.add(filename)
 
     def update_touched(self, filenames):
         for f in filenames:
             self.mark_touched(f)
 
-    @property
+    @util.propertycache
     def copied_from_p1(self):
         return self._p1_copies.copy()
 
     def mark_copied_from_p1(self, source, dest):
+        if 'copied_from_p1' in vars(self):
+            del self.copied_from_p1
         self._p1_copies[dest] = source
 
     def update_copies_from_p1(self, copies):
         for dest, source in copies.items():
             self.mark_copied_from_p1(source, dest)
 
-    @property
+    @util.propertycache
     def copied_from_p2(self):
         return self._p2_copies.copy()
 
     def mark_copied_from_p2(self, source, dest):
+        if 'copied_from_p2' in vars(self):
+            del self.copied_from_p2
         self._p2_copies[dest] = source
 
     def update_copies_from_p2(self, copies):