summaryrefslogtreecommitdiff
path: root/Objects/frameobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-08-01 18:50:33 +0000
committerGuido van Rossum <guido@python.org>2002-08-01 18:50:33 +0000
commitf4be427c46c4508a9c2a14f5fd224ef6721784aa (patch)
tree415614077f852aaf31779cda9f2ef060ffa01268 /Objects/frameobject.c
parent0a3d6060d53da872729997807e1f564dbbb8c550 (diff)
downloadcpython-git-f4be427c46c4508a9c2a14f5fd224ef6721784aa.tar.gz
Tim found that once test_longexp has run, test_sort takes very much
longer to run than normal. A profiler run showed that this was due to PyFrame_New() taking up an unreasonable amount of time. A little thinking showed that this was due to the while loop clearing the space available for the stack. The solution is to only clear the local variables (and cells and free variables), not the space available for the stack, since anything beyond the stack top is considered to be garbage anyway. Also, use memset() instead of a while loop counting backwards. This should be a time savings for normal code too! (By a probably unmeasurable amount. :-)
Diffstat (limited to 'Objects/frameobject.c')
-rw-r--r--Objects/frameobject.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 6adc0364aa..dfb3a2ec53 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -265,8 +265,6 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals,
if (f == NULL)
return NULL;
}
- else
- extras = f->ob_size;
_Py_NewReference((PyObject *)f);
}
if (builtins == NULL) {
@@ -317,10 +315,10 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals,
f->f_ncells = ncells;
f->f_nfreevars = nfrees;
- while (--extras >= 0)
- f->f_localsplus[extras] = NULL;
+ extras = f->f_nlocals + ncells + nfrees;
+ memset(f->f_localsplus, 0, extras * sizeof(f->f_localsplus[0]));
- f->f_valuestack = f->f_localsplus + (f->f_nlocals + ncells + nfrees);
+ f->f_valuestack = f->f_localsplus + extras;
f->f_stacktop = f->f_valuestack;
_PyObject_GC_TRACK(f);
return f;