summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-04-23 15:24:50 (GMT)
committerBenjamin Peterson <benjamin@python.org>2012-04-23 15:24:50 (GMT)
commit7d95e4072169911b228c9e42367afb5f17fd3db0 (patch)
treed07731f1b71b1eb5f653778141ca586069d216b1 /Python
parent80d07f825108761af9fe2ac79c1ef50289c07c08 (diff)
downloadcpython-7d95e4072169911b228c9e42367afb5f17fd3db0.zip
cpython-7d95e4072169911b228c9e42367afb5f17fd3db0.tar.gz
cpython-7d95e4072169911b228c9e42367afb5f17fd3db0.tar.bz2
Implement PEP 412: Key-sharing dictionaries (closes #13903)
Patch from Mark Shannon.
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c75
1 files changed, 18 insertions, 57 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index fde7841..a4e5a32 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -2123,70 +2123,31 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
w = GETITEM(names, oparg);
if (PyDict_CheckExact(f->f_globals)
&& PyDict_CheckExact(f->f_builtins)) {
- if (PyUnicode_CheckExact(w)) {
- /* Inline the PyDict_GetItem() calls.
- WARNING: this is an extreme speed hack.
- Do not try this at home. */
- Py_hash_t hash = ((PyASCIIObject *)w)->hash;
- if (hash != -1) {
- PyDictObject *d;
- PyDictEntry *e;
- d = (PyDictObject *)(f->f_globals);
- e = d->ma_lookup(d, w, hash);
- if (e == NULL) {
- x = NULL;
- break;
- }
- x = e->me_value;
- if (x != NULL) {
- Py_INCREF(x);
- PUSH(x);
- DISPATCH();
- }
- d = (PyDictObject *)(f->f_builtins);
- e = d->ma_lookup(d, w, hash);
- if (e == NULL) {
- x = NULL;
- break;
- }
- x = e->me_value;
- if (x != NULL) {
- Py_INCREF(x);
- PUSH(x);
- DISPATCH();
- }
- goto load_global_error;
- }
+ x = _PyDict_LoadGlobal((PyDictObject *)f->f_globals,
+ (PyDictObject *)f->f_builtins,
+ w);
+ if (x == NULL) {
+ if (!PyErr_Occurred())
+ format_exc_check_arg(PyExc_NameError,
+ GLOBAL_NAME_ERROR_MSG, w);
+ break;
}
- /* This is the un-inlined version of the code above */
- x = PyDict_GetItem(f->f_globals, w);
+ }
+ else {
+ /* Slow-path if globals or builtins is not a dict */
+ x = PyObject_GetItem(f->f_globals, w);
if (x == NULL) {
- x = PyDict_GetItem(f->f_builtins, w);
+ x = PyObject_GetItem(f->f_builtins, w);
if (x == NULL) {
- load_global_error:
- format_exc_check_arg(
- PyExc_NameError,
- GLOBAL_NAME_ERROR_MSG, w);
+ if (PyErr_ExceptionMatches(PyExc_KeyError))
+ format_exc_check_arg(
+ PyExc_NameError,
+ GLOBAL_NAME_ERROR_MSG, w);
break;
}
}
- Py_INCREF(x);
- PUSH(x);
- DISPATCH();
- }
-
- /* Slow-path if globals or builtins is not a dict */
- x = PyObject_GetItem(f->f_globals, w);
- if (x == NULL) {
- x = PyObject_GetItem(f->f_builtins, w);
- if (x == NULL) {
- if (PyErr_ExceptionMatches(PyExc_KeyError))
- format_exc_check_arg(
- PyExc_NameError,
- GLOBAL_NAME_ERROR_MSG, w);
- break;
- }
}
+ Py_INCREF(x);
PUSH(x);
DISPATCH();