# HG changeset patch # User Yuya Nishihara # Date 2015-08-14 06:52:19 # Node ID 607868eccaa7a351f604f3d5b62734b9670270df # Parent 5049e10fed1444f272e03f4bd0678ad10c3fec8b 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. diff --git a/mercurial/parsers.c b/mercurial/parsers.c --- a/mercurial/parsers.c +++ b/mercurial/parsers.c @@ -1148,11 +1148,9 @@ static PyObject *reachableroots2(indexOb 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 @@ static PyObject *reachableroots2(indexOb 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 @@ static PyObject *reachableroots2(indexOb 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); } }