changeset 27063:37e1fdcb271c

context: optimize _parents() This patch avoids some extra attribute lookups and list mutations. This micro-optimization seems to result in a minor speedup for `hg log` on my Firefox repo: before: 25.35s after: 24.91s delta: -0.44s (98% of original) Not the biggest gain. But every little bit helps.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 21 Nov 2015 19:04:12 -0800
parents e4f2e4f5e98d
children a29db426c5ba
files mercurial/context.py
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/context.py	Sun Nov 22 13:05:21 2015 -0500
+++ b/mercurial/context.py	Sat Nov 21 19:04:12 2015 -0800
@@ -511,10 +511,11 @@
 
     @propertycache
     def _parents(self):
-        p = self._repo.changelog.parentrevs(self._rev)
-        if p[1] == nullrev:
-            p = p[:-1]
-        return [changectx(self._repo, x) for x in p]
+        repo = self._repo
+        p1, p2 = repo.changelog.parentrevs(self._rev)
+        if p2 == nullrev:
+            return [changectx(repo, p1)]
+        return [changectx(repo, p1), changectx(repo, p2)]
 
     def changeset(self):
         return self._changeset