Patchwork D8565: mergestate: optimize unresolvedcount() a little bit

login
register
mail settings
Submitter phabricator
Date May 18, 2020, 10:10 p.m.
Message ID <differential-rev-PHID-DREV-izn7am6ha5zjwmxkwe2w-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46352/
State Superseded
Headers show

Comments

phabricator - May 18, 2020, 10:10 p.m.
durin42 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  It struck me as wasteful to make this extra list copy of a generator. I was
  hoping to manage to return a bool instead of an int (and thus avoid traversing
  the dictionary past the first unresolved entry) but at least one caller cares
  about the count and this is the easy way forward while still making me
  marginally happier.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/mergestate.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/mergestate.py b/mercurial/mergestate.py
--- a/mercurial/mergestate.py
+++ b/mercurial/mergestate.py
@@ -79,6 +79,12 @@ 
 ACTION_GET_OTHER_AND_STORE = b'gs'
 
 
+_MERGE_UNRESOLVED_STATES = {
+    MERGE_RECORD_UNRESOLVED,
+    MERGE_RECORD_UNRESOLVED_PATH,
+}
+
+
 class mergestate(object):
     '''track 3-way merge state of individual files
 
@@ -569,10 +575,7 @@ 
         """Obtain the paths of unresolved files."""
 
         for f, entry in pycompat.iteritems(self._state):
-            if entry[0] in (
-                MERGE_RECORD_UNRESOLVED,
-                MERGE_RECORD_UNRESOLVED_PATH,
-            ):
+            if entry[0] in _MERGE_UNRESOLVED_STATES:
                 yield f
 
     def driverresolved(self):
@@ -713,7 +716,13 @@ 
 
     def unresolvedcount(self):
         """get unresolved count for this merge (persistent)"""
-        return len(list(self.unresolved()))
+        return len(
+            [
+                None
+                for entry in pycompat.itervalues(self._state)
+                if entry[0] in _MERGE_UNRESOLVED_STATES
+            ]
+        )
 
     def actions(self):
         """return lists of actions to perform on the dirstate"""