summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-02-19 20:48:26 (GMT)
committerGuido van Rossum <guido@python.org>1998-02-19 20:48:26 (GMT)
commitbde6ff7984df185a793cb39461c9605c8162cef5 (patch)
tree3b66fe5b5a28742c52f18469245d63d04123a04b
parent3da3fcef961c4be22806d9d94df5f1d0f09dbbc7 (diff)
downloadcpython-bde6ff7984df185a793cb39461c9605c8162cef5.zip
cpython-bde6ff7984df185a793cb39461c9605c8162cef5.tar.gz
cpython-bde6ff7984df185a793cb39461c9605c8162cef5.tar.bz2
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.
-rw-r--r--Objects/frameobject.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 03f54dd..0b9604a 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);