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

This commit is contained in:
Guido van Rossum 1996-10-08 14:18:42 +00:00
parent cf1474b73a
commit c196202e3d

View File

@ -68,20 +68,33 @@ 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;
if (filler == NULL) {
filler = Py_BuildValue("(ii)", -1, -1);
if (filler == NULL)
return NULL;
}
v = PyTuple_New(RE_NREGS);
if (v == NULL)
return NULL;
for (i = 0; i < RE_NREGS; i++) { for (i = 0; i < RE_NREGS; i++) {
int lo = regs->start[i];
int hi = regs->end[i];
PyObject *w; PyObject *w;
w = Py_BuildValue("(ii)", regs->start[i], regs->end[i]); if (lo == -1 && hi == -1) {
w = filler;
Py_INCREF(w);
}
else
w = Py_BuildValue("(ii)", lo, hi);
if (w == NULL) { if (w == NULL) {
Py_XDECREF(v); Py_XDECREF(v);
v = NULL; return NULL;
break;
} }
PyTuple_SetItem(v, i, w); PyTuple_SetItem(v, i, w);
} }
}
return v; return v;
} }