Commit 0d936939 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Fast-path PyDict_GetItem

Not only does this improve perfomance, but it somehow improves performance
consistency as well.
parent 9030ec59
......@@ -249,6 +249,16 @@ extern "C" int PyDict_SetItemString(PyObject* mp, const char* key, PyObject* ite
extern "C" PyObject* PyDict_GetItem(PyObject* dict, PyObject* key) noexcept {
ASSERT(isSubclass(dict->cls, dict_cls) || dict->cls == attrwrapper_cls, "%s", getTypeName(dict));
if (isSubclass(dict->cls, dict_cls)) {
BoxedDict* d = static_cast<BoxedDict*>(dict);
auto it = d->d.find(key);
if (it != d->d.end())
return it->second;
return NULL;
}
// This path doesn't exist in CPython; we have it to support extension modules that do
// something along the lines of PyDict_GetItem(PyModule_GetDict()):
try {
return getitem(dict, key);
} catch (ExcInfo e) {
......
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