Remove dead code in _PyDict_GetItemHint and rename to _PyDict_LookupIndex (GH-95948)

This commit is contained in:
Matthias Görgens 2022-08-18 17:19:21 +08:00 committed by GitHub
parent 586fc02be5
commit 4a6fa89465
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 51 deletions

View file

@ -1686,50 +1686,12 @@ PyDict_GetItem(PyObject *op, PyObject *key)
}
Py_ssize_t
_PyDict_GetItemHint(PyDictObject *mp, PyObject *key,
Py_ssize_t hint, PyObject **value)
_PyDict_LookupIndex(PyDictObject *mp, PyObject *key)
{
assert(*value == NULL);
PyObject *value;
assert(PyDict_CheckExact((PyObject*)mp));
assert(PyUnicode_CheckExact(key));
if (hint >= 0 && hint < mp->ma_keys->dk_nentries) {
PyObject *res = NULL;
if (DK_IS_UNICODE(mp->ma_keys)) {
PyDictUnicodeEntry *ep = DK_UNICODE_ENTRIES(mp->ma_keys) + (size_t)hint;
if (ep->me_key == key) {
if (mp->ma_keys->dk_kind == DICT_KEYS_SPLIT) {
assert(mp->ma_values != NULL);
res = mp->ma_values->values[(size_t)hint];
}
else {
res = ep->me_value;
}
if (res != NULL) {
*value = res;
return hint;
}
}
}
else {
PyDictKeyEntry *ep = DK_ENTRIES(mp->ma_keys) + (size_t)hint;
if (ep->me_key == key) {
if (mp->ma_keys->dk_kind == DICT_KEYS_SPLIT) {
assert(mp->ma_values != NULL);
res = mp->ma_values->values[(size_t)hint];
}
else {
res = ep->me_value;
}
if (res != NULL) {
*value = res;
return hint;
}
}
}
}
Py_hash_t hash = unicode_get_hash(key);
if (hash == -1) {
hash = PyObject_Hash(key);
@ -1738,7 +1700,7 @@ _PyDict_GetItemHint(PyDictObject *mp, PyObject *key,
}
}
return _Py_dict_lookup(mp, key, hash, value);
return _Py_dict_lookup(mp, key, hash, &value);
}
/* Same as PyDict_GetItemWithError() but with hash supplied by caller.