phases: fix performance regression with Python 2
Unlike Python 3, xrange doesn't support efficient "in" and uses a linear
time scan instead. Expand the condition to handle it fast.
Differential Revision: https://phab.mercurial-scm.org/D9072
--- a/mercurial/phases.py Wed Sep 23 09:04:32 2020 -0700
+++ b/mercurial/phases.py Wed Sep 23 14:44:21 2020 +0200
@@ -282,26 +282,28 @@
while low < high:
mid = (low + high) // 2
revs = data[mid][0]
+ revs_low = revs[0]
+ revs_high = revs[-1]
- if rev in revs:
+ if rev >= revs_low and rev <= revs_high:
_sortedrange_split(data, mid, rev, t)
return
- if revs[0] == rev + 1:
+ if revs_low == rev + 1:
if mid and data[mid - 1][0][-1] == rev:
_sortedrange_split(data, mid - 1, rev, t)
else:
_sortedrange_insert(data, mid, rev, t)
return
- if revs[-1] == rev - 1:
+ if revs_high == rev - 1:
if mid + 1 < len(data) and data[mid + 1][0][0] == rev:
_sortedrange_split(data, mid + 1, rev, t)
else:
_sortedrange_insert(data, mid + 1, rev, t)
return
- if revs[0] > rev:
+ if revs_low > rev:
high = mid
else:
low = mid + 1