Patchwork D2232: treemanifest: add an optimized __nonzero__()

login
register
mail settings
Submitter phabricator
Date Feb. 14, 2018, 5:15 a.m.
Message ID <343e59cfc2eb707fc73c248e3a475975@localhost.localdomain>
Download mbox | patch
Permalink /patch/27878/
State Not Applicable
Headers show

Comments

phabricator - Feb. 14, 2018, 5:15 a.m.
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




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

Patch

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