changeset 30875:1791be8a95c5

localrepo: avoid unnecessary conversion from node to rev changelog.heads() first calls headrevs then converts them to nodes. localrepo.heads() then sorts them using self.changelog.rev function and makes useless conversion back to revs. Instead let's call changelog.headrevs() from localrepo.heads(), sort the output and then convert to nodes. Because headrevs does not support start parameter this optimization only works if start is None.
author Stanislau Hlebik <stash@fb.com>
date Thu, 02 Feb 2017 02:56:38 -0800
parents 1f51b4658f21
children 3a4c0905f357
files mercurial/localrepo.py
diffstat 1 files changed, 4 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/localrepo.py	Thu Feb 02 14:19:48 2017 +0100
+++ b/mercurial/localrepo.py	Thu Feb 02 02:56:38 2017 -0800
@@ -1852,6 +1852,10 @@
                                   listsubrepos)
 
     def heads(self, start=None):
+        if start is None:
+            headrevs = sorted(self.changelog.headrevs(), reverse=True)
+            return [self.changelog.node(rev) for rev in headrevs]
+
         heads = self.changelog.heads(start)
         # sort the output in rev descending order
         return sorted(heads, key=self.changelog.rev, reverse=True)