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.
--- 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