Commit b07c0871 authored by Guido van Rossum's avatar Guido van Rossum

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.
parent edfae893
...@@ -164,9 +164,16 @@ PyFrame_New(tstate, code, globals, locals) ...@@ -164,9 +164,16 @@ PyFrame_New(tstate, code, globals, locals)
PyErr_BadInternalCall(); PyErr_BadInternalCall();
return NULL; return NULL;
} }
if (back == NULL || back->f_globals != globals) {
builtins = PyDict_GetItem(globals, builtin_object); builtins = PyDict_GetItem(globals, builtin_object);
if (builtins != NULL && PyModule_Check(builtins)) if (builtins != NULL && PyModule_Check(builtins))
builtins = PyModule_GetDict(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)) if (builtins != NULL && !PyDict_Check(builtins))
builtins = NULL; builtins = NULL;
if (free_list == NULL) { if (free_list == NULL) {
...@@ -194,9 +201,13 @@ PyFrame_New(tstate, code, globals, locals) ...@@ -194,9 +201,13 @@ PyFrame_New(tstate, code, globals, locals)
_Py_NewReference(f); _Py_NewReference(f);
} }
if (builtins == NULL) { if (builtins == NULL) {
/* No builtins! Make up a minimal one. */
builtins = PyDict_New(); builtins = PyDict_New();
if (builtins == NULL) if (builtins == NULL)
return NULL; return NULL;
/* Give them 'None', at least. */
if (PyDict_SetItemString(builtins, "None", Py_None) < 0)
return NULL;
} }
else else
Py_XINCREF(builtins); Py_XINCREF(builtins);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment