Skip to content

Commit f9e999c

Browse files
committed
Use _PyDict_GetItemHint instead of _Py_dict_lookup to determine index in dictionary when specializing.
1 parent d890943 commit f9e999c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Python/specialize.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,26 +227,27 @@ specialize_module_load_attr(
227227
_PyAdaptiveEntry *cache0, _PyLoadAttrCache *cache1)
228228
{
229229
PyModuleObject *m = (PyModuleObject *)owner;
230-
PyObject *attr, *getattr;
230+
PyObject *value = NULL;
231+
PyObject *getattr;
231232
_Py_IDENTIFIER(__getattr__);
232233
PyDictObject *dict = (PyDictObject *)m->md_dict;
233234
if (dict == NULL) {
234235
return -1;
235236
}
236-
getattr = _PyDict_GetItemIdWithError(m->md_dict, &PyId___getattr__);
237-
if (PyErr_Occurred()) {
238-
PyErr_Clear();
237+
if (dict->ma_keys->dk_kind != DICT_KEYS_UNICODE) {
239238
return -1;
240239
}
241-
if (getattr != NULL) {
240+
getattr = _PyUnicode_FromId(&PyId___getattr__); /* borrowed */
241+
if (getattr == NULL) {
242+
PyErr_Clear();
242243
return -1;
243244
}
244-
Py_hash_t hash = PyObject_Hash(name);
245-
if (hash == -1) {
246-
PyErr_Clear();
245+
Py_ssize_t index = _PyDict_GetItemHint(dict, getattr, -1, &value);
246+
assert(index != DKIX_ERROR);
247+
if (index != DKIX_EMPTY) {
247248
return -1;
248249
}
249-
Py_ssize_t index = _Py_dict_lookup(dict, name, hash, &attr);
250+
index = _PyDict_GetItemHint(dict, name, -1, &value);
250251
assert (index != DKIX_ERROR);
251252
if (index != (uint16_t)index) {
252253
return -1;

0 commit comments

Comments
 (0)