delta-find: use sets instead of list in the snapshot cache
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sun, 06 Nov 2022 17:55:46 -0500
changeset 49679 b670eb3dd6c9
parent 49678 efbbc2f9121e
child 49680 40e24d82b513
delta-find: use sets instead of list in the snapshot cache This seems more appropriate.
mercurial/cext/revlog.c
mercurial/revlogutils/deltas.py
tests/test-revlog-raw.py
--- a/mercurial/cext/revlog.c	Sun Nov 06 16:56:23 2022 -0500
+++ b/mercurial/cext/revlog.c	Sun Nov 06 17:55:46 2022 -0500
@@ -1489,7 +1489,7 @@
 		}
 		if (allvalues == NULL) {
 			int r;
-			allvalues = PyList_New(0);
+			allvalues = PySet_New(0);
 			if (!allvalues) {
 				goto bail;
 			}
@@ -1500,7 +1500,7 @@
 			}
 		}
 		value = PyLong_FromSsize_t(rev);
-		if (PyList_Append(allvalues, value)) {
+		if (PySet_Add(allvalues, value)) {
 			goto bail;
 		}
 		Py_CLEAR(key);
--- a/mercurial/revlogutils/deltas.py	Sun Nov 06 16:56:23 2022 -0500
+++ b/mercurial/revlogutils/deltas.py	Sun Nov 06 17:55:46 2022 -0500
@@ -989,8 +989,7 @@
     __slots__ = ('snapshots', '_start_rev', '_end_rev')
 
     def __init__(self):
-        # XXX should probably be a set ?
-        self.snapshots = collections.defaultdict(list)
+        self.snapshots = collections.defaultdict(set)
         self._start_rev = None
         self._end_rev = None
 
@@ -1038,7 +1037,7 @@
             issnapshot = revlog.issnapshot
             for rev in revlog.revs(start_rev, end_rev):
                 if issnapshot(rev):
-                    cache[deltaparent(rev)].append(rev)
+                    cache[deltaparent(rev)].add(rev)
 
 
 class deltacomputer:
--- a/tests/test-revlog-raw.py	Sun Nov 06 16:56:23 2022 -0500
+++ b/tests/test-revlog-raw.py	Sun Nov 06 17:55:46 2022 -0500
@@ -466,8 +466,8 @@
         print('  got:      %s' % result)
 
 
-snapshotmapall = {0: [6, 8, 11, 17, 19, 25], 8: [21], -1: [0, 30]}
-snapshotmap15 = {0: [17, 19, 25], 8: [21], -1: [30]}
+snapshotmapall = {0: {6, 8, 11, 17, 19, 25}, 8: {21}, -1: {0, 30}}
+snapshotmap15 = {0: {17, 19, 25}, 8: {21}, -1: {30}}
 
 
 def findsnapshottest(rlog):