8000 gh-134043: use stackrefs for dict lookup in `_PyObject_GetMethodStackRef` by kumaraditya303 · Pull Request #136412 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-134043: use stackrefs for dict lookup in _PyObject_GetMethodStackRef #136412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Next Next commit
use stackrefs for dict loopkup
  • Loading branch information
kumaraditya303 committed Jul 8, 2025
commit 3108bbe38ff126100024addfdb9b7dd5587e5e18
28 changes: 19 additions & 9 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1753,19 +1753,29 @@ _PyObject_GetMethodStackRef(PyThreadState *ts, PyObject *obj,
}
}
if (dict != NULL) {
// TODO: use _Py_dict_lookup_threadsafe_stackref
assert(PyUnicode_CheckExact(name));
Py_hash_t hash = _PyObject_HashFast(name);
// cannot fail for exact unicode
assert(hash != -1);
Py_INCREF(dict);
PyObject *value;
if (PyDict_GetItemRef(dict, name, &value) != 0) {
// found or error
Py_DECREF(dict);
// ref is not visible to gc so there should be
// no escaping calls before assigning it to method
_PyStackRef ref;
Py_ssize_t ix = _Py_dict_lookup_threadsafe_stackref((PyDictObject *)dict,
name, hash, &ref);
if (ix == DKIX_ERROR) {
// error
PyStackRef_CLEAR(*method);
if (value != NULL) {
*method = PyStackRef_FromPyObjectSteal(value);
}
Py_DECREF(dict);
return -1;
} else if (!PyStackRef_IsNull(ref)) {
// found
_PyStackRef tmp = *method;
*method = ref;
PyStackRef_XCLOSE(tmp);
Py_DECREF(dict);
return 0;
}
// not found
Py_DECREF(dict);
}

Expand Down
Loading
0