repoview: use a heap in _getstatichidden
authorPierre-Yves David <pierre-yves.david@fb.com>
Fri, 03 Apr 2015 14:16:50 -0700
changeset 24616 72d34c5a6614
parent 24615 9e558b788daa
child 24617 f76595f6ed7c
repoview: use a heap in _getstatichidden Since we want to process all non-public changesets from top to bottom, a heap seems more appropriate. This will ensure any revision is processed after all its children, opening the way to code simplification.
mercurial/repoview.py
--- a/mercurial/repoview.py	Fri Apr 03 13:58:12 2015 -0700
+++ b/mercurial/repoview.py	Fri Apr 03 14:16:50 2015 -0700
@@ -6,7 +6,7 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
-import collections
+import heapq
 import copy
 import error
 import phases
@@ -39,9 +39,13 @@
         actuallyhidden = {}
         getphase = repo._phasecache.phase
         getparentrevs = repo.changelog.parentrevs
-        queue = collections.deque((r, False) for r in repo.changelog.headrevs())
-        while queue:
-            rev, blocked = queue.popleft()
+        heap = [(-r, False) for r in repo.changelog.headrevs()]
+        heapq.heapify(heap)
+        heappop = heapq.heappop
+        heappush = heapq.heappush
+        while heap:
+            rev, blocked = heappop(heap)
+            rev = - rev
             phase = getphase(repo, rev)
             # Skip nodes which are public (guaranteed to not be hidden) and
             # nodes which have already been processed and won't be blocked by
@@ -57,7 +61,7 @@
                 blocked = True
 
             for parent in (p for p in getparentrevs(rev) if p != nullrev):
-                queue.append((parent, blocked))
+                heappush(heap, (- parent, blocked))
     return set(rev for rev, hidden in actuallyhidden.iteritems() if hidden)
 
 def _getdynamicblockers(repo):