From bde6ff7984df185a793cb39461c9605c8162cef5 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 19 Feb 1998 20:48:26 +0000 Subject: [PATCH] Vladimir Marangozov' performance hack: copy f_builtins from ancestor if the globals are the same. Also, when creating a dummy builtins dictionary, add "None" to it, just to be kind. --- Objects/frameobject.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 03f54dd947..0b9604ae71 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -164,9 +164,16 @@ PyFrame_New(tstate, code, globals, locals) PyErr_BadInternalCall(); return NULL; } - builtins = PyDict_GetItem(globals, builtin_object); - if (builtins != NULL && PyModule_Check(builtins)) - builtins = PyModule_GetDict(builtins); + if (back == NULL || back->f_globals != globals) { + builtins = PyDict_GetItem(globals, builtin_object); + if (builtins != NULL && PyModule_Check(builtins)) + builtins = PyModule_GetDict(builtins); + } + else { + /* If we share the globals, we share the builtins. + Save a lookup and a call. */ + builtins = back->f_builtins; + } if (builtins != NULL && !PyDict_Check(builtins)) builtins = NULL; if (free_list == NULL) { @@ -194,9 +201,13 @@ PyFrame_New(tstate, code, globals, locals) _Py_NewReference(f); } if (builtins == NULL) { + /* No builtins! Make up a minimal one. */ builtins = PyDict_New(); if (builtins == NULL) return NULL; + /* Give them 'None', at least. */ + if (PyDict_SetItemString(builtins, "None", Py_None) < 0) + return NULL; } else Py_XINCREF(builtins); -- 2.40.0