D2232: treemanifest: add an optimized __nonzero__()

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Wed Feb 14 05:15:26 UTC 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHGdbb131ffdc4d: treemanifest: add an optimized __nonzero__() (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2232?vs=5654&id=5684

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

AFFECTED FILES
  mercurial/manifest.py

CHANGE DETAILS

diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -755,6 +755,12 @@
             size += m.__len__()
         return size
 
+    def __nonzero__(self):
+        # Faster than "__len() != 0" since it avoids loading sub-manifests
+        return not self._isempty()
+
+    __bool__ = __nonzero__
+
     def _isempty(self):
         self._load() # for consistency; already loaded by all callers
         return (not self._files and (not self._dirs or



To: martinvonz, #hg-reviewers, indygreg
Cc: indygreg, mercurial-devel


More information about the Mercurial-devel mailing list