@@ -1597,19 +1597,11 @@ insertion_resize(PyInterpreterState *interp, PyDictObject *mp, int unicode)
15971597}
15981598
15991599static Py_ssize_t
1600- insert_into_splitdictkeys_locked (PyDictKeysObject * keys , PyObject * name )
1600+ insert_into_splitdictkeys (PyDictKeysObject * keys , PyObject * name , Py_hash_t hash )
16011601{
16021602 assert (PyUnicode_CheckExact (name ));
16031603 ASSERT_KEYS_LOCKED (keys );
16041604
1605- Py_hash_t hash = unicode_get_hash (name );
1606- if (hash == -1 ) {
1607- hash = PyUnicode_Type .tp_hash (name );
1608- if (hash == -1 ) {
1609- PyErr_Clear ();
1610- return DKIX_EMPTY ;
1611- }
1612- }
16131605 Py_ssize_t ix = unicodekeys_lookup_unicode (keys , name , hash );
16141606 if (ix == DKIX_EMPTY ) {
16151607 if (keys -> dk_usable <= 0 ) {
@@ -1629,15 +1621,6 @@ insert_into_splitdictkeys_locked(PyDictKeysObject *keys, PyObject *name)
16291621 return ix ;
16301622}
16311623
1632- static Py_ssize_t
1633- insert_into_splitdictkeys (PyDictKeysObject * keys , PyObject * name )
1634- {
1635- LOCK_KEYS (keys );
1636- Py_ssize_t ix = insert_into_splitdictkeys_locked (keys , name );
1637- UNLOCK_KEYS (keys );
1638- return ix ;
1639- }
1640-
16411624static inline int
16421625insert_combined_dict (PyInterpreterState * interp , PyDictObject * mp ,
16431626 Py_hash_t hash , PyObject * key , PyObject * value )
@@ -6701,24 +6684,23 @@ _PyObject_StoreInstanceAttribute(PyObject *obj, PyDictValues *values,
67016684 assert (Py_TYPE (obj )-> tp_flags & Py_TPFLAGS_MANAGED_DICT );
67026685 Py_ssize_t ix = DKIX_EMPTY ;
67036686 if (PyUnicode_CheckExact (name )) {
6704- #ifdef Py_GIL_DISABLED
67056687 Py_hash_t hash = unicode_get_hash (name );
67066688 if (hash == -1 ) {
67076689 hash = PyUnicode_Type .tp_hash (name );
6708- if (hash == -1 ) {
6709- PyErr_Clear ();
6710- return DKIX_EMPTY ;
6711- }
6690+ assert (hash != -1 );
67126691 }
67136692
6693+ #ifdef Py_GIL_DISABLED
67146694 // Try a thread-safe lookup to see if the index is already allocated
67156695 ix = unicodekeys_lookup_unicode_threadsafe (keys , name , hash );
67166696 if (ix == DKIX_EMPTY ) {
6717- // Fall back to a version that will lock and maybe insert
6718- ix = insert_into_splitdictkeys (keys , name );
6697+ // Lock keys and do insert
6698+ LOCK_KEYS (keys );
6699+ ix = insert_into_splitdictkeys (keys , name , hash );
6700+ UNLOCK_KEYS (keys );
67196701 }
67206702#else
6721- ix = insert_into_splitdictkeys (keys , name );
6703+ ix = insert_into_splitdictkeys (keys , name , hash );
67226704#endif
67236705
67246706#ifdef Py_STATS
0 commit comments