comparison mercurial/parsers.c @ 26055:607868eccaa7

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.
author Yuya Nishihara <yuya@tcha.org>
date Fri, 14 Aug 2015 15:52:19 +0900
parents 5049e10fed14
children e7fe0a12376c
comparison
equal deleted inserted replaced
26054:5049e10fed14 26055:607868eccaa7
1146 1146
1147 if (includepatharg == Py_True) 1147 if (includepatharg == Py_True)
1148 includepath = 1; 1148 includepath = 1;
1149 1149
1150 /* Initialize return set */ 1150 /* Initialize return set */
1151 reachable = PySet_New(NULL); 1151 reachable = PyList_New(0);
1152 if (reachable == NULL) { 1152 if (reachable == NULL)
1153 PyErr_NoMemory();
1154 goto bail; 1153 goto bail;
1155 }
1156 1154
1157 /* Initialize internal datastructures */ 1155 /* Initialize internal datastructures */
1158 tovisit = (int *)malloc((len + 1) * sizeof(int)); 1156 tovisit = (int *)malloc((len + 1) * sizeof(int));
1159 if (tovisit == NULL) { 1157 if (tovisit == NULL) {
1160 PyErr_NoMemory(); 1158 PyErr_NoMemory();
1203 if (revstates[revnum + 1] & RS_ROOT) { 1201 if (revstates[revnum + 1] & RS_ROOT) {
1204 revstates[revnum + 1] |= RS_REACHABLE; 1202 revstates[revnum + 1] |= RS_REACHABLE;
1205 val = PyInt_FromLong(revnum); 1203 val = PyInt_FromLong(revnum);
1206 if (val == NULL) 1204 if (val == NULL)
1207 goto bail; 1205 goto bail;
1208 PySet_Add(reachable, val); 1206 PyList_Append(reachable, val);
1209 Py_DECREF(val); 1207 Py_DECREF(val);
1210 if (includepath == 0) 1208 if (includepath == 0)
1211 continue; 1209 continue;
1212 } 1210 }
1213 1211
1239 /* Corrupted index file, error is set from 1237 /* Corrupted index file, error is set from
1240 * index_get_parents */ 1238 * index_get_parents */
1241 if (r < 0) 1239 if (r < 0)
1242 goto bail; 1240 goto bail;
1243 for (k = 0; k < 2; k++) { 1241 for (k = 0; k < 2; k++) {
1244 if (revstates[parents[k] + 1] & RS_REACHABLE) { 1242 if ((revstates[parents[k] + 1] & RS_REACHABLE)
1243 && !(revstates[i + 1] & RS_REACHABLE)) {
1245 revstates[i + 1] |= RS_REACHABLE; 1244 revstates[i + 1] |= RS_REACHABLE;
1246 val = PyInt_FromLong(i); 1245 val = PyInt_FromLong(i);
1247 if (val == NULL) 1246 if (val == NULL)
1248 goto bail; 1247 goto bail;
1249 PySet_Add(reachable, val); 1248 PyList_Append(reachable, val);
1250 Py_DECREF(val); 1249 Py_DECREF(val);
1251 } 1250 }
1252 } 1251 }
1253 } 1252 }
1254 } 1253 }