mirror of https://github.com/python/cpython
Remove dead code in _PyDict_GetItemHint and rename to _PyDict_LookupIndex (GH-95948)
This commit is contained in:
parent
586fc02be5
commit
4a6fa89465
|
@ -62,7 +62,7 @@ extern Py_ssize_t _PyDict_KeysSize(PyDictKeysObject *keys);
|
|||
*/
|
||||
extern Py_ssize_t _Py_dict_lookup(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject **value_addr);
|
||||
|
||||
extern Py_ssize_t _PyDict_GetItemHint(PyDictObject *, PyObject *, Py_ssize_t, PyObject **);
|
||||
extern Py_ssize_t _PyDict_LookupIndex(PyDictObject *, PyObject *);
|
||||
extern Py_ssize_t _PyDictKeys_StringLookup(PyDictKeysObject* dictkeys, PyObject *key);
|
||||
extern PyObject *_PyDict_LoadGlobal(PyDictObject *, PyDictObject *, PyObject *);
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -511,7 +511,6 @@ specialize_module_load_attr(PyObject *owner, _Py_CODEUNIT *instr,
|
|||
{
|
||||
_PyAttrCache *cache = (_PyAttrCache *)(instr + 1);
|
||||
PyModuleObject *m = (PyModuleObject *)owner;
|
||||
PyObject *value = NULL;
|
||||
assert((owner->ob_type->tp_flags & Py_TPFLAGS_MANAGED_DICT) == 0);
|
||||
PyDictObject *dict = (PyDictObject *)m->md_dict;
|
||||
if (dict == NULL) {
|
||||
|
@ -522,14 +521,13 @@ specialize_module_load_attr(PyObject *owner, _Py_CODEUNIT *instr,
|
|||
SPECIALIZATION_FAIL(opcode, SPEC_FAIL_ATTR_NON_STRING_OR_SPLIT);
|
||||
return -1;
|
||||
}
|
||||
Py_ssize_t index = _PyDict_GetItemHint(dict, &_Py_ID(__getattr__), -1,
|
||||
&value);
|
||||
Py_ssize_t index = _PyDict_LookupIndex(dict, &_Py_ID(__getattr__));
|
||||
assert(index != DKIX_ERROR);
|
||||
if (index != DKIX_EMPTY) {
|
||||
SPECIALIZATION_FAIL(opcode, SPEC_FAIL_ATTR_MODULE_ATTR_NOT_FOUND);
|
||||
return -1;
|
||||
}
|
||||
index = _PyDict_GetItemHint(dict, name, -1, &value);
|
||||
index = _PyDict_LookupIndex(dict, name);
|
||||
assert (index != DKIX_ERROR);
|
||||
if (index != (uint16_t)index) {
|
||||
SPECIALIZATION_FAIL(opcode, SPEC_FAIL_OUT_OF_RANGE);
|
||||
|
@ -703,14 +701,13 @@ specialize_dict_access(
|
|||
return 0;
|
||||
}
|
||||
// We found an instance with a __dict__.
|
||||
PyObject *value = NULL;
|
||||
Py_ssize_t hint =
|
||||
_PyDict_GetItemHint(dict, name, -1, &value);
|
||||
if (hint != (uint16_t)hint) {
|
||||
Py_ssize_t index =
|
||||
_PyDict_LookupIndex(dict, name);
|
||||
if (index != (uint16_t)index) {
|
||||
SPECIALIZATION_FAIL(base_op, SPEC_FAIL_OUT_OF_RANGE);
|
||||
return 0;
|
||||
}
|
||||
cache->index = (uint16_t)hint;
|
||||
cache->index = (uint16_t)index;
|
||||
write_u32(cache->version, type->tp_version_tag);
|
||||
_Py_SET_OPCODE(*instr, hint_op);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue