summaryrefslogtreecommitdiffstats
path: root/Modules/regexmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-10-08 14:18:42 (GMT)
committerGuido van Rossum <guido@python.org>1996-10-08 14:18:42 (GMT)
commitc196202e3d809be6d457b1ad06f13f4361e868aa (patch)
tree5e590d035eee0f9716ce7c9139942ed1c64a5c16 /Modules/regexmodule.c
parentcf1474b73ad3e4085af220f3845b75b201974d38 (diff)
downloadcpython-c196202e3d809be6d457b1ad06f13f4361e868aa.zip
cpython-c196202e3d809be6d457b1ad06f13f4361e868aa.tar.gz
cpython-c196202e3d809be6d457b1ad06f13f4361e868aa.tar.bz2
Speedup of makeresult() by keeping a filler of (-1, -1) around.
Diffstat (limited to 'Modules/regexmodule.c')
-rw-r--r--Modules/regexmodule.c37
1 files changed, 25 insertions, 12 deletions
diff --git a/Modules/regexmodule.c b/Modules/regexmodule.c
index 1c553ea..6f566c3 100644
--- a/Modules/regexmodule.c
+++ b/Modules/regexmodule.c
@@ -68,19 +68,32 @@ static PyObject *
makeresult(regs)
struct re_registers *regs;
{
- PyObject *v = PyTuple_New(RE_NREGS);
- if (v != NULL) {
- int i;
- for (i = 0; i < RE_NREGS; i++) {
- PyObject *w;
- w = Py_BuildValue("(ii)", regs->start[i], regs->end[i]);
- if (w == NULL) {
- Py_XDECREF(v);
- v = NULL;
- break;
- }
- PyTuple_SetItem(v, i, w);
+ PyObject *v;
+ 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++) {
+ 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;
}