changeset 45550:29a259be6424

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
author Joerg Sonnenberger <joerg@bec.de>
date Wed, 23 Sep 2020 14:44:21 +0200
parents e9468f14379a
children 4c8d9b53b1c7
files mercurial/phases.py
diffstat 1 files changed, 6 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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