From 8d823a70755d358e6db56e83ce5d76bc9e8a1bcf Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Mon, 30 Dec 2002 22:29:22 +0000 Subject: SF #561244, Micro optimizations Initialize the small integers and __builtins__ in startup. This removes some if conditions. Change XDECREF to DECREF for values which shouldn't be NULL. --- Objects/frameobject.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'Objects/frameobject.c') diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 9123d94283..b982064c0e 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -401,9 +401,9 @@ frame_dealloc(PyFrameObject *f) } Py_XDECREF(f->f_back); - Py_XDECREF(f->f_code); - Py_XDECREF(f->f_builtins); - Py_XDECREF(f->f_globals); + Py_DECREF(f->f_code); + Py_DECREF(f->f_builtins); + Py_DECREF(f->f_globals); Py_XDECREF(f->f_locals); Py_XDECREF(f->f_trace); Py_XDECREF(f->f_exc_type); @@ -525,21 +525,23 @@ PyTypeObject PyFrame_Type = { 0, /* tp_dict */ }; +static PyObject *builtin_object; + +int PyFrame_Init() +{ + builtin_object = PyString_InternFromString("__builtins__"); + return (builtin_object != NULL); +} + PyFrameObject * PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals, PyObject *locals) { PyFrameObject *back = tstate->frame; - static PyObject *builtin_object; PyFrameObject *f; PyObject *builtins; int extras, ncells, nfrees; - if (builtin_object == NULL) { - builtin_object = PyString_InternFromString("__builtins__"); - if (builtin_object == NULL) - return NULL; - } #ifdef Py_DEBUG if (code == NULL || globals == NULL || !PyDict_Check(globals) || (locals != NULL && !PyDict_Check(locals))) { @@ -802,4 +804,6 @@ PyFrame_Fini(void) --numfree; } assert(numfree == 0); + Py_XDECREF(builtin_object); + builtin_object = NULL; } -- cgit v1.2.1