@@ -2136,13 +2136,6 @@ tuple_tuple_add(PyObject *lhs, PyObject *rhs)
21362136/* sequence * int helpers: bypass PyNumber_Multiply dispatch overhead
21372137 by calling sq_repeat directly with PyLong_AsSsize_t. */
21382138
2139- extern PyObject * unicode_repeat (PyObject * str , Py_ssize_t n );
2140- extern PyObject * bytes_repeat (PyObject * self , Py_ssize_t n );
2141- extern PyObject * bytes_concat (PyObject * a , PyObject * b );
2142- extern PyObject * tuple_repeat (PyObject * self , Py_ssize_t n );
2143- extern PyObject * dict_or (PyObject * self , PyObject * other );
2144- extern PyObject * dict_ior (PyObject * self , PyObject * other );
2145-
21462139static inline PyObject *
21472140seq_int_multiply (PyObject * seq , PyObject * n ,
21482141 ssizeargfunc repeat )
@@ -2171,13 +2164,15 @@ int_str_guard(PyObject *lhs, PyObject *rhs)
21712164static PyObject *
21722165str_int_multiply (PyObject * lhs , PyObject * rhs )
21732166{
2174- return seq_int_multiply (lhs , rhs , unicode_repeat );
2167+ return seq_int_multiply (lhs , rhs ,
2168+ PyUnicode_Type .tp_as_sequence -> sq_repeat );
21752169}
21762170
21772171static PyObject *
21782172int_str_multiply (PyObject * lhs , PyObject * rhs )
21792173{
2180- return seq_int_multiply (rhs , lhs , unicode_repeat );
2174+ return seq_int_multiply (rhs , lhs ,
2175+ PyUnicode_Type .tp_as_sequence -> sq_repeat );
21812176}
21822177
21832178/* bytes-bytes */
@@ -2188,6 +2183,12 @@ bytes_bytes_guard(PyObject *lhs, PyObject *rhs)
21882183 return PyBytes_CheckExact (lhs ) && PyBytes_CheckExact (rhs );
21892184}
21902185
2186+ static PyObject *
2187+ bytes_bytes_add (PyObject * lhs , PyObject * rhs )
2188+ {
2189+ return PyBytes_Type .tp_as_sequence -> sq_concat (lhs , rhs );
2190+ }
2191+
21912192/* bytes-int and int-bytes */
21922193
21932194static int
@@ -2205,13 +2206,15 @@ int_bytes_guard(PyObject *lhs, PyObject *rhs)
22052206static PyObject *
22062207bytes_int_multiply (PyObject * lhs , PyObject * rhs )
22072208{
2208- return seq_int_multiply (lhs , rhs , bytes_repeat );
2209+ return seq_int_multiply (lhs , rhs ,
2210+ PyBytes_Type .tp_as_sequence -> sq_repeat );
22092211}
22102212
22112213static PyObject *
22122214int_bytes_multiply (PyObject * lhs , PyObject * rhs )
22132215{
2214- return seq_int_multiply (rhs , lhs , bytes_repeat );
2216+ return seq_int_multiply (rhs , lhs ,
2217+ PyBytes_Type .tp_as_sequence -> sq_repeat );
22152218}
22162219
22172220/* tuple-int and int-tuple */
@@ -2231,13 +2234,15 @@ int_tuple_guard(PyObject *lhs, PyObject *rhs)
22312234static PyObject *
22322235tuple_int_multiply (PyObject * lhs , PyObject * rhs )
22332236{
2234- return seq_int_multiply (lhs , rhs , tuple_repeat );
2237+ return seq_int_multiply (lhs , rhs ,
2238+ PyTuple_Type .tp_as_sequence -> sq_repeat );
22352239}
22362240
22372241static PyObject *
22382242int_tuple_multiply (PyObject * lhs , PyObject * rhs )
22392243{
2240- return seq_int_multiply (rhs , lhs , tuple_repeat );
2244+ return seq_int_multiply (rhs , lhs ,
2245+ PyTuple_Type .tp_as_sequence -> sq_repeat );
22412246}
22422247
22432248/* dict-dict */
@@ -2248,6 +2253,18 @@ dict_dict_guard(PyObject *lhs, PyObject *rhs)
22482253 return PyDict_CheckExact (lhs ) && PyDict_CheckExact (rhs );
22492254}
22502255
2256+ static PyObject *
2257+ dict_dict_or (PyObject * lhs , PyObject * rhs )
2258+ {
2259+ return PyDict_Type .tp_as_number -> nb_or (lhs , rhs );
2260+ }
2261+
2262+ static PyObject *
2263+ dict_dict_ior (PyObject * lhs , PyObject * rhs )
2264+ {
2265+ return PyDict_Type .tp_as_number -> nb_inplace_or (lhs , rhs );
2266+ }
2267+
22512268static int
22522269compactlongs_guard (PyObject * lhs , PyObject * rhs )
22532270{
@@ -2373,10 +2390,10 @@ static _PyBinaryOpSpecializationDescr binaryop_extend_descrs[] = {
23732390 {NB_INPLACE_MULTIPLY , str_int_guard , str_int_multiply , & PyUnicode_Type , 0 , & PyUnicode_Type , & PyLong_Type },
23742391 {NB_INPLACE_MULTIPLY , int_str_guard , int_str_multiply , & PyUnicode_Type , 0 , & PyLong_Type , & PyUnicode_Type },
23752392
2376- /* bytes + bytes: call bytes_concat directly. bytes_concat may return
2377- an operand when one side is empty, so result is not always unique. */
2378- {NB_ADD , bytes_bytes_guard , bytes_concat , & PyBytes_Type , 0 , & PyBytes_Type , & PyBytes_Type },
2379- {NB_INPLACE_ADD , bytes_bytes_guard , bytes_concat , & PyBytes_Type , 0 , & PyBytes_Type , & PyBytes_Type },
2393+ /* bytes + bytes: bytes_concat may return an operand when one side
2394+ is empty, so result is not always unique. */
2395+ {NB_ADD , bytes_bytes_guard , bytes_bytes_add , & PyBytes_Type , 0 , & PyBytes_Type , & PyBytes_Type },
2396+ {NB_INPLACE_ADD , bytes_bytes_guard , bytes_bytes_add , & PyBytes_Type , 0 , & PyBytes_Type , & PyBytes_Type },
23802397
23812398 /* bytes * int / int * bytes: call bytes_repeat directly.
23822399 bytes_repeat returns the original when n == 1. */
@@ -2392,9 +2409,9 @@ static _PyBinaryOpSpecializationDescr binaryop_extend_descrs[] = {
23922409 {NB_INPLACE_MULTIPLY , tuple_int_guard , tuple_int_multiply , & PyTuple_Type , 0 , & PyTuple_Type , & PyLong_Type },
23932410 {NB_INPLACE_MULTIPLY , int_tuple_guard , int_tuple_multiply , & PyTuple_Type , 0 , & PyLong_Type , & PyTuple_Type },
23942411
2395- /* dict | dict: call dict_or directly */
2396- {NB_OR , dict_dict_guard , dict_or , & PyDict_Type , 1 , & PyDict_Type , & PyDict_Type },
2397- {NB_INPLACE_OR , dict_dict_guard , dict_ior , & PyDict_Type , 0 , & PyDict_Type , & PyDict_Type },
2412+ /* dict | dict */
2413+ {NB_OR , dict_dict_guard , dict_dict_or , & PyDict_Type , 1 , & PyDict_Type , & PyDict_Type },
2414+ {NB_INPLACE_OR , dict_dict_guard , dict_dict_ior , & PyDict_Type , 0 , & PyDict_Type , & PyDict_Type },
23982415};
23992416
24002417static int
0 commit comments