mirror of
https://github.com/python/cpython.git
synced 2025-10-22 22:53:06 +00:00
Move check for str-only keys in LOAD_GLOBAL specializations to specialization time. (GH-31659)
This commit is contained in:
parent
10117f1d8c
commit
b35603532b
2 changed files with 14 additions and 15 deletions
|
@ -1595,19 +1595,6 @@ is_method(PyObject **stack_pointer, int args) {
|
||||||
return PEEK(args+2) != NULL;
|
return PEEK(args+2) != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
|
||||||
dictkeys_get_value_by_index(PyDictKeysObject *dk, int index)
|
|
||||||
{
|
|
||||||
if (DK_IS_UNICODE(dk)) {
|
|
||||||
PyDictUnicodeEntry *ep = DK_UNICODE_ENTRIES(dk) + index;
|
|
||||||
return ep->me_value;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
PyDictKeyEntry *ep = DK_ENTRIES(dk) + index;
|
|
||||||
return ep->me_value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define KWNAMES_LEN() \
|
#define KWNAMES_LEN() \
|
||||||
(call_shape.kwnames == NULL ? 0 : ((int)PyTuple_GET_SIZE(call_shape.kwnames)))
|
(call_shape.kwnames == NULL ? 0 : ((int)PyTuple_GET_SIZE(call_shape.kwnames)))
|
||||||
|
|
||||||
|
@ -3043,7 +3030,9 @@ handle_eval_breaker:
|
||||||
_PyLoadGlobalCache *cache = (_PyLoadGlobalCache *)next_instr;
|
_PyLoadGlobalCache *cache = (_PyLoadGlobalCache *)next_instr;
|
||||||
uint32_t version = read32(&cache->module_keys_version);
|
uint32_t version = read32(&cache->module_keys_version);
|
||||||
DEOPT_IF(dict->ma_keys->dk_version != version, LOAD_GLOBAL);
|
DEOPT_IF(dict->ma_keys->dk_version != version, LOAD_GLOBAL);
|
||||||
PyObject *res = dictkeys_get_value_by_index(dict->ma_keys, cache->index);
|
assert(DK_IS_UNICODE(dict->ma_keys));
|
||||||
|
PyDictUnicodeEntry *entries = DK_UNICODE_ENTRIES(dict->ma_keys);
|
||||||
|
PyObject *res = entries[cache->index].me_value;
|
||||||
DEOPT_IF(res == NULL, LOAD_GLOBAL);
|
DEOPT_IF(res == NULL, LOAD_GLOBAL);
|
||||||
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_GLOBAL);
|
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_GLOBAL);
|
||||||
STAT_INC(LOAD_GLOBAL, hit);
|
STAT_INC(LOAD_GLOBAL, hit);
|
||||||
|
@ -3063,7 +3052,9 @@ handle_eval_breaker:
|
||||||
uint16_t bltn_version = cache->builtin_keys_version;
|
uint16_t bltn_version = cache->builtin_keys_version;
|
||||||
DEOPT_IF(mdict->ma_keys->dk_version != mod_version, LOAD_GLOBAL);
|
DEOPT_IF(mdict->ma_keys->dk_version != mod_version, LOAD_GLOBAL);
|
||||||
DEOPT_IF(bdict->ma_keys->dk_version != bltn_version, LOAD_GLOBAL);
|
DEOPT_IF(bdict->ma_keys->dk_version != bltn_version, LOAD_GLOBAL);
|
||||||
PyObject *res = dictkeys_get_value_by_index(bdict->ma_keys, cache->index);
|
assert(DK_IS_UNICODE(bdict->ma_keys));
|
||||||
|
PyDictUnicodeEntry *entries = DK_UNICODE_ENTRIES(bdict->ma_keys);
|
||||||
|
PyObject *res = entries[cache->index].me_value;
|
||||||
DEOPT_IF(res == NULL, LOAD_GLOBAL);
|
DEOPT_IF(res == NULL, LOAD_GLOBAL);
|
||||||
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_GLOBAL);
|
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_GLOBAL);
|
||||||
STAT_INC(LOAD_GLOBAL, hit);
|
STAT_INC(LOAD_GLOBAL, hit);
|
||||||
|
|
|
@ -1219,6 +1219,10 @@ _Py_Specialize_LoadGlobal(
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
PyDictKeysObject * globals_keys = ((PyDictObject *)globals)->ma_keys;
|
PyDictKeysObject * globals_keys = ((PyDictObject *)globals)->ma_keys;
|
||||||
|
if (!DK_IS_UNICODE(globals_keys)) {
|
||||||
|
SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_LOAD_GLOBAL_NON_STRING_OR_SPLIT);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
Py_ssize_t index = _PyDictKeys_StringLookup(globals_keys, name);
|
Py_ssize_t index = _PyDictKeys_StringLookup(globals_keys, name);
|
||||||
if (index == DKIX_ERROR) {
|
if (index == DKIX_ERROR) {
|
||||||
SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_LOAD_GLOBAL_NON_STRING_OR_SPLIT);
|
SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_LOAD_GLOBAL_NON_STRING_OR_SPLIT);
|
||||||
|
@ -1241,6 +1245,10 @@ _Py_Specialize_LoadGlobal(
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
PyDictKeysObject * builtin_keys = ((PyDictObject *)builtins)->ma_keys;
|
PyDictKeysObject * builtin_keys = ((PyDictObject *)builtins)->ma_keys;
|
||||||
|
if (!DK_IS_UNICODE(builtin_keys)) {
|
||||||
|
SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_LOAD_GLOBAL_NON_STRING_OR_SPLIT);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
index = _PyDictKeys_StringLookup(builtin_keys, name);
|
index = _PyDictKeys_StringLookup(builtin_keys, name);
|
||||||
if (index == DKIX_ERROR) {
|
if (index == DKIX_ERROR) {
|
||||||
SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_LOAD_GLOBAL_NON_STRING_OR_SPLIT);
|
SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_LOAD_GLOBAL_NON_STRING_OR_SPLIT);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue