Mercurial > hg
comparison mercurial/cext/revlog.c @ 39226:7a759ad2d06d
shortest: use nodetree for finding shortest node within revset
This speeds up `hg log -T '{shortest(node,1)}\n'` in my repo from 12s
to 4.5s. That's very close to the 4.1s it takes without the
disambiguation revset configured. My repo has 69.5k revisions, of
which 550 were in the configured revset ("not public()").
Differential Revision: https://phab.mercurial-scm.org/D4120
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Sun, 05 Aug 2018 00:42:07 -0700 |
parents | fcaffbd7e635 |
children | 42cc76d0f836 |
comparison
equal
deleted
inserted
replaced
39225:fcaffbd7e635 | 39226:7a759ad2d06d |
---|---|
1085 } | 1085 } |
1086 | 1086 |
1087 return -1; | 1087 return -1; |
1088 } | 1088 } |
1089 | 1089 |
1090 static PyObject *nt_insert_py(nodetree *self, PyObject *args) | |
1091 { | |
1092 Py_ssize_t rev; | |
1093 const char *node; | |
1094 if (!PyArg_ParseTuple(args, "n", &rev)) | |
1095 return NULL; | |
1096 const Py_ssize_t length = index_length(self->index); | |
1097 if (rev < 0 || rev >= length) { | |
1098 PyErr_SetString(PyExc_ValueError, "revlog index out of range"); | |
1099 return NULL; | |
1100 } | |
1101 node = index_node_existing(self->index, rev); | |
1102 if (nt_insert(self, node, rev) == -1) | |
1103 return NULL; | |
1104 Py_RETURN_NONE; | |
1105 } | |
1106 | |
1090 static int nt_delete_node(nodetree *self, const char *node) | 1107 static int nt_delete_node(nodetree *self, const char *node) |
1091 { | 1108 { |
1092 /* rev==-2 happens to get encoded as 0, which is interpreted as not set */ | 1109 /* rev==-2 happens to get encoded as 0, which is interpreted as not set */ |
1093 return nt_insert(self, node, -2); | 1110 return nt_insert(self, node, -2); |
1094 } | 1111 } |
1179 */ | 1196 */ |
1180 PyErr_SetString(PyExc_Exception, "broken node tree"); | 1197 PyErr_SetString(PyExc_Exception, "broken node tree"); |
1181 return -3; | 1198 return -3; |
1182 } | 1199 } |
1183 | 1200 |
1201 static PyObject *nt_shortest_py(nodetree *self, PyObject *args) | |
1202 { | |
1203 PyObject *val; | |
1204 char *node; | |
1205 int length; | |
1206 | |
1207 if (!PyArg_ParseTuple(args, "O", &val)) | |
1208 return NULL; | |
1209 if (node_check(val, &node) == -1) | |
1210 return NULL; | |
1211 | |
1212 length = nt_shortest(self, node); | |
1213 if (length == -3) | |
1214 return NULL; | |
1215 if (length == -2) { | |
1216 raise_revlog_error(); | |
1217 return NULL; | |
1218 } | |
1219 return PyInt_FromLong(length); | |
1220 } | |
1221 | |
1184 static void nt_dealloc(nodetree *self) | 1222 static void nt_dealloc(nodetree *self) |
1185 { | 1223 { |
1186 Py_XDECREF(self->index); | 1224 Py_XDECREF(self->index); |
1187 free(self->nodes); | 1225 free(self->nodes); |
1188 self->nodes = NULL; | 1226 self->nodes = NULL; |
1189 PyObject_Del(self); | 1227 PyObject_Del(self); |
1190 } | 1228 } |
1229 | |
1230 static PyMethodDef nt_methods[] = { | |
1231 {"insert", (PyCFunction)nt_insert_py, METH_VARARGS, | |
1232 "insert an index entry"}, | |
1233 {"shortest", (PyCFunction)nt_shortest_py, METH_VARARGS, | |
1234 "find length of shortest hex nodeid of a binary ID"}, | |
1235 {NULL} /* Sentinel */ | |
1236 }; | |
1191 | 1237 |
1192 static PyTypeObject nodetreeType = { | 1238 static PyTypeObject nodetreeType = { |
1193 PyVarObject_HEAD_INIT(NULL, 0) /* header */ | 1239 PyVarObject_HEAD_INIT(NULL, 0) /* header */ |
1194 "parsers.nodetree", /* tp_name */ | 1240 "parsers.nodetree", /* tp_name */ |
1195 sizeof(nodetree) , /* tp_basicsize */ | 1241 sizeof(nodetree) , /* tp_basicsize */ |
1215 0, /* tp_clear */ | 1261 0, /* tp_clear */ |
1216 0, /* tp_richcompare */ | 1262 0, /* tp_richcompare */ |
1217 0, /* tp_weaklistoffset */ | 1263 0, /* tp_weaklistoffset */ |
1218 0, /* tp_iter */ | 1264 0, /* tp_iter */ |
1219 0, /* tp_iternext */ | 1265 0, /* tp_iternext */ |
1220 0, /* tp_methods */ | 1266 nt_methods, /* tp_methods */ |
1221 0, /* tp_members */ | 1267 0, /* tp_members */ |
1222 0, /* tp_getset */ | 1268 0, /* tp_getset */ |
1223 0, /* tp_base */ | 1269 0, /* tp_base */ |
1224 0, /* tp_dict */ | 1270 0, /* tp_dict */ |
1225 0, /* tp_descr_get */ | 1271 0, /* tp_descr_get */ |