@@ -167,26 +167,8 @@ dummy_func(void) {
167167 op (_STORE_SUBSCR_DICT , (value , dict_st , sub -- st )) {
168168 PyObject * sub_o = sym_get_const (ctx , sub );
169169 if (sub_o != NULL ) {
170- if (PyUnicode_CheckExact (sub_o ) || PyLong_CheckExact (sub_o ) || PyBytes_CheckExact (sub_o )
171- || PyFloat_CheckExact (sub_o ) || PyComplex_CheckExact (sub_o )) {
172- // PyObject_Hash can't fail on these types
173- ADD_OP (_STORE_SUBSCR_DICT_KNOWN_HASH , 0 , PyObject_Hash (sub_o ));
174- }
175- else if (PyTuple_CheckExact (sub_o )) {
176- // only use known hash variant when hash of tuple is already computed
177- // since computing it can call arbitrary code
178- Py_hash_t hash = ((PyTupleObject * )sub_o )-> ob_hash ;
179- if (hash != -1 ) {
180- ADD_OP (_STORE_SUBSCR_DICT_KNOWN_HASH , 0 , hash );
181- }
182- }
183- else if (Py_TYPE (sub_o )-> tp_hash == PyBaseObject_Type .tp_hash ) {
184- // for user-defined objects which don't override tp_hash
185- Py_hash_t hash = PyObject_Hash (sub_o );
186- ADD_OP (_STORE_SUBSCR_DICT_KNOWN_HASH , 0 , hash );
187- PyType_Watch (TYPE_WATCHER_ID , Py_TYPE (sub_o ));
188- _Py_BloomFilter_Add (dependencies , Py_TYPE (sub_o ));
189- }
170+ optimize_dict_known_hash (ctx , dependencies , this_instr ,
171+ sub_o , _STORE_SUBSCR_DICT_KNOWN_HASH );
190172 }
191173 (void )value ;
192174 st = dict_st ;
@@ -507,26 +489,8 @@ dummy_func(void) {
507489 op (_BINARY_OP_SUBSCR_DICT , (dict_st , sub_st -- res , ds , ss )) {
508490 PyObject * sub = sym_get_const (ctx , sub_st );
509491 if (sub != NULL ) {
510- if (PyUnicode_CheckExact (sub ) || PyLong_CheckExact (sub ) || PyBytes_CheckExact (sub )
511- || PyFloat_CheckExact (sub ) || PyComplex_CheckExact (sub )) {
512- // PyObject_Hash can't fail on these types
513- ADD_OP (_BINARY_OP_SUBSCR_DICT_KNOWN_HASH , 0 , PyObject_Hash (sub ));
514- }
515- else if (PyTuple_CheckExact (sub )) {
516- // only use known hash variant when hash of tuple is already computed
517- // since computing it can call arbitrary code
518- Py_hash_t hash = ((PyTupleObject * )sub )-> ob_hash ;
519- if (hash != -1 ) {
520- ADD_OP (_BINARY_OP_SUBSCR_DICT_KNOWN_HASH , 0 , hash );
521- }
522- }
523- else if (Py_TYPE (sub )-> tp_hash == PyBaseObject_Type .tp_hash ) {
524- // for user-defined objects which don't override tp_hash
525- Py_hash_t hash = PyObject_Hash (sub );
526- ADD_OP (_BINARY_OP_SUBSCR_DICT_KNOWN_HASH , 0 , hash );
527- PyType_Watch (TYPE_WATCHER_ID , Py_TYPE (sub ));
528- _Py_BloomFilter_Add (dependencies , Py_TYPE (sub ));
529- }
492+ optimize_dict_known_hash (ctx , dependencies , this_instr ,
493+ sub , _BINARY_OP_SUBSCR_DICT_KNOWN_HASH );
530494 }
531495 res = sym_new_not_null (ctx );
532496 ds = dict_st ;
0 commit comments