Mercurial > public > mercurial-scm > hg-stable
diff mercurial/ancestor.py @ 25639:7125225a5287
ancestors: prefetch method outside of the loop
15412bba5a68 is yet another example where this is worthwhile when it comes to
performance, we blindly do it for all 'lazyancestors' methods.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Wed, 24 Jun 2015 12:37:55 -0500 |
parents | 0ca8410ea345 |
children | 7ef98b38163f |
line wrap: on
line diff
--- a/mercurial/ancestor.py Sun Sep 28 20:18:43 2014 -0700 +++ b/mercurial/ancestor.py Wed Jun 24 12:37:55 2015 -0500 @@ -316,11 +316,14 @@ stoprev = self._stoprev visit = collections.deque(revs) + see = seen.add + schedule = visit.append + while visit: for parent in parentrevs(visit.popleft()): if parent >= stoprev and parent not in seen: - visit.append(parent) - seen.add(parent) + schedule(parent) + see(parent) yield parent def __contains__(self, target): @@ -337,6 +340,7 @@ stoprev = self._stoprev heappop = heapq.heappop heappush = heapq.heappush + see = seen.add targetseen = False @@ -347,7 +351,7 @@ # We need to make sure we push all parents into the heap so # that we leave it in a consistent state for future calls. heappush(visit, -parent) - seen.add(parent) + see(parent) if parent == target: targetseen = True