reachableroots: return list of revisions instead of set
Now we don't need a set of reachable revisions, and the caller wants a sorted
list of revisions, so constructing a set is just a waste of time.
revset #0: 0::tip
2) 0.002536
3) 0.001598 63%
PyList_New() should set an appropriate exception on error, so we don't need
to call PyErr_NoMemory() manually.
This patch lacks error handling of PyList_Append() as it was before for
PySet_Add(). It should be fixed later.
--- a/mercurial/parsers.c Fri Aug 14 15:49:11 2015 +0900
+++ b/mercurial/parsers.c Fri Aug 14 15:52:19 2015 +0900
@@ -1148,11 +1148,9 @@
includepath = 1;
/* Initialize return set */
- reachable = PySet_New(NULL);
- if (reachable == NULL) {
- PyErr_NoMemory();
+ reachable = PyList_New(0);
+ if (reachable == NULL)
goto bail;
- }
/* Initialize internal datastructures */
tovisit = (int *)malloc((len + 1) * sizeof(int));
@@ -1205,7 +1203,7 @@
val = PyInt_FromLong(revnum);
if (val == NULL)
goto bail;
- PySet_Add(reachable, val);
+ PyList_Append(reachable, val);
Py_DECREF(val);
if (includepath == 0)
continue;
@@ -1241,12 +1239,13 @@
if (r < 0)
goto bail;
for (k = 0; k < 2; k++) {
- if (revstates[parents[k] + 1] & RS_REACHABLE) {
+ if ((revstates[parents[k] + 1] & RS_REACHABLE)
+ && !(revstates[i + 1] & RS_REACHABLE)) {
revstates[i + 1] |= RS_REACHABLE;
val = PyInt_FromLong(i);
if (val == NULL)
goto bail;
- PySet_Add(reachable, val);
+ PyList_Append(reachable, val);
Py_DECREF(val);
}
}