@@ -1129,13 +1129,16 @@ dictkeys_generic_lookup(PyDictObject *mp, PyDictKeysObject* dk, PyObject *key, P
11291129 return do_lookup (mp , dk , key , hash , compare_generic );
11301130}
11311131
1132- static Py_hash_t
1133- check_keys_and_hash (PyDictKeysObject * dk , PyObject * key )
1132+ static bool
1133+ check_keys_unicode (PyDictKeysObject * dk , PyObject * key )
11341134{
1135- DictKeysKind kind = dk -> dk_kind ;
1136- if (!PyUnicode_CheckExact (key ) || kind == DICT_KEYS_GENERAL ) {
1137- return -1 ;
1138- }
1135+ return PyUnicode_CheckExact (key ) && (dk -> dk_kind != DICT_KEYS_GENERAL );
1136+ }
1137+
1138+ Py_ssize_t
1139+ hash_unicode_key (PyObject * key )
1140+ {
1141+ assert (PyUnicode_CheckExact (key ));
11391142 Py_hash_t hash = unicode_get_hash (key );
11401143 if (hash == -1 ) {
11411144 hash = PyUnicode_Type .tp_hash (key );
@@ -1182,22 +1185,21 @@ unicodekeys_lookup_split(PyDictKeysObject* dk, PyObject *key, Py_hash_t hash)
11821185Py_ssize_t
11831186_PyDictKeys_StringLookup (PyDictKeysObject * dk , PyObject * key )
11841187{
1185- Py_hash_t hash = check_keys_and_hash (dk , key );
1186- if (hash == -1 ) {
1188+ if (!check_keys_unicode (dk , key )) {
11871189 return DKIX_ERROR ;
11881190 }
1191+ Py_hash_t hash = hash_unicode_key (key );
11891192 return unicodekeys_lookup_unicode (dk , key , hash );
11901193}
11911194
11921195Py_ssize_t
11931196_PyDictKeys_StringLookupAndVersion (PyDictKeysObject * dk , PyObject * key , uint32_t * version )
11941197{
1195- Py_hash_t hash = check_keys_and_hash (dk , key );
1196- if (hash == -1 ) {
1198+ if (!check_keys_unicode (dk , key )) {
11971199 return DKIX_ERROR ;
11981200 }
1199-
12001201 Py_ssize_t ix ;
1202+ Py_hash_t hash = hash_unicode_key (key );
12011203 LOCK_KEYS (dk );
12021204 ix = unicodekeys_lookup_unicode (dk , key , hash );
12031205 * version = _PyDictKeys_GetVersionForCurrentState (_PyInterpreterState_GET (), dk );
0 commit comments