phases: fix performance regression with Python 2
authorJoerg Sonnenberger <joerg@bec.de>
Wed, 23 Sep 2020 14:44:21 +0200
changeset 45550 29a259be6424
parent 45549 e9468f14379a
child 45551 4c8d9b53b1c7
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
mercurial/phases.py
--- 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