Commit 1996fd69 authored by Guido van Rossum's avatar Guido van Rossum

Speedup of makeresult() by keeping a filler of (-1, -1) around.

parent 7a0232ab
...@@ -68,19 +68,32 @@ static PyObject * ...@@ -68,19 +68,32 @@ static PyObject *
makeresult(regs) makeresult(regs)
struct re_registers *regs; struct re_registers *regs;
{ {
PyObject *v = PyTuple_New(RE_NREGS); PyObject *v;
if (v != NULL) { int i;
int i; static PyObject *filler = NULL;
for (i = 0; i < RE_NREGS; i++) { if (filler == NULL) {
PyObject *w; filler = Py_BuildValue("(ii)", -1, -1);
w = Py_BuildValue("(ii)", regs->start[i], regs->end[i]); if (filler == NULL)
if (w == NULL) { return NULL;
Py_XDECREF(v); }
v = NULL; v = PyTuple_New(RE_NREGS);
break; if (v == NULL)
} return NULL;
PyTuple_SetItem(v, i, w); for (i = 0; i < RE_NREGS; i++) {
int lo = regs->start[i];
int hi = regs->end[i];
PyObject *w;
if (lo == -1 && hi == -1) {
w = filler;
Py_INCREF(w);
}
else
w = Py_BuildValue("(ii)", lo, hi);
if (w == NULL) {
Py_XDECREF(v);
return NULL;
} }
PyTuple_SetItem(v, i, w);
} }
return v; return v;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment