diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-11-20 08:24:02 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-11-20 08:24:02 (GMT) |
commit | b4efc963d628475c79f02ecf43a4ec564b46428e (patch) | |
tree | ee70295f62c6e30bf45acf29bd9617c1b4802a9f /Python | |
parent | c50ec007ff1b08fd2677bdd1d785b0e0af2588df (diff) | |
download | cpython-b4efc963d628475c79f02ecf43a4ec564b46428e.zip cpython-b4efc963d628475c79f02ecf43a4ec564b46428e.tar.gz cpython-b4efc963d628475c79f02ecf43a4ec564b46428e.tar.bz2 |
Issue #25557: Refactor _PyDict_LoadGlobal()
Don't fallback to PyDict_GetItemWithError() if the hash is unknown: compute the
hash instead. Add also comments to explain the optimization a little bit.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ceval.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 7f9ef6f..1d65649 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2347,26 +2347,33 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) PyObject *name = GETITEM(names, oparg); PyObject *v; if (PyDict_CheckExact(f->f_globals) - && PyDict_CheckExact(f->f_builtins)) { + && PyDict_CheckExact(f->f_builtins)) + { v = _PyDict_LoadGlobal((PyDictObject *)f->f_globals, (PyDictObject *)f->f_builtins, name); if (v == NULL) { - if (!_PyErr_OCCURRED()) + if (!_PyErr_OCCURRED()) { + /* _PyDict_LoadGlobal() returns NULL without raising + * an exception if the key doesn't exist */ format_exc_check_arg(PyExc_NameError, NAME_ERROR_MSG, name); + } goto error; } Py_INCREF(v); } else { /* Slow-path if globals or builtins is not a dict */ + + /* namespace 1: globals */ v = PyObject_GetItem(f->f_globals, name); if (v == NULL) { if (!PyErr_ExceptionMatches(PyExc_KeyError)) goto error; PyErr_Clear(); + /* namespace 2: builtins */ v = PyObject_GetItem(f->f_builtins, name); if (v == NULL) { if (PyErr_ExceptionMatches(PyExc_KeyError)) |