@@ -2122,54 +2122,64 @@ is_compactlong(PyObject *v)
21222122 _PyLong_IsCompact ((PyLongObject * )v );
21232123}
21242124
2125- /* sequence * int helpers: bypass PyNumber_Multiply dispatch overhead
2126- by calling sq_repeat directly with PyLong_AsSsize_t. */
2127-
2128- static inline PyObject *
2129- seq_int_multiply (PyObject * seq , PyObject * n ,
2130- ssizeargfunc repeat )
2125+ static PyObject *
2126+ str_int_multiply (PyObject * lhs , PyObject * rhs )
21312127{
2132- Py_ssize_t count = PyLong_AsSsize_t (n );
2128+ Py_ssize_t count = PyLong_AsSsize_t (rhs );
21332129 if (count == -1 && PyErr_Occurred ()) {
21342130 return NULL ;
21352131 }
2136- return repeat (seq , count );
2137- }
2138-
2139- static PyObject *
2140- str_int_multiply (PyObject * lhs , PyObject * rhs )
2141- {
2142- return seq_int_multiply (lhs , rhs , PyUnicode_Type .tp_as_sequence -> sq_repeat );
2132+ return _PyUnicode_Repeat (lhs , count );
21432133}
21442134
21452135static PyObject *
21462136int_str_multiply (PyObject * lhs , PyObject * rhs )
21472137{
2148- return seq_int_multiply (rhs , lhs , PyUnicode_Type .tp_as_sequence -> sq_repeat );
2138+ Py_ssize_t count = PyLong_AsSsize_t (lhs );
2139+ if (count == -1 && PyErr_Occurred ()) {
2140+ return NULL ;
2141+ }
2142+ return _PyUnicode_Repeat (rhs , count );
21492143}
21502144
21512145static PyObject *
21522146bytes_int_multiply (PyObject * lhs , PyObject * rhs )
21532147{
2154- return seq_int_multiply (lhs , rhs , PyBytes_Type .tp_as_sequence -> sq_repeat );
2148+ Py_ssize_t count = PyLong_AsSsize_t (rhs );
2149+ if (count == -1 && PyErr_Occurred ()) {
2150+ return NULL ;
2151+ }
2152+ return _PyBytes_Repeat (lhs , count );
21552153}
21562154
21572155static PyObject *
21582156int_bytes_multiply (PyObject * lhs , PyObject * rhs )
21592157{
2160- return seq_int_multiply (rhs , lhs , PyBytes_Type .tp_as_sequence -> sq_repeat );
2158+ Py_ssize_t count = PyLong_AsSsize_t (lhs );
2159+ if (count == -1 && PyErr_Occurred ()) {
2160+ return NULL ;
2161+ }
2162+ return _PyBytes_Repeat (rhs , count );
21612163}
21622164
21632165static PyObject *
21642166tuple_int_multiply (PyObject * lhs , PyObject * rhs )
21652167{
2166- return seq_int_multiply (lhs , rhs , PyTuple_Type .tp_as_sequence -> sq_repeat );
2168+ Py_ssize_t count = PyLong_AsSsize_t (rhs );
2169+ if (count == -1 && PyErr_Occurred ()) {
2170+ return NULL ;
2171+ }
2172+ return _PyTuple_Repeat (lhs , count );
21672173}
21682174
21692175static PyObject *
21702176int_tuple_multiply (PyObject * lhs , PyObject * rhs )
21712177{
2172- return seq_int_multiply (rhs , lhs , PyTuple_Type .tp_as_sequence -> sq_repeat );
2178+ Py_ssize_t count = PyLong_AsSsize_t (lhs );
2179+ if (count == -1 && PyErr_Occurred ()) {
2180+ return NULL ;
2181+ }
2182+ return _PyTuple_Repeat (rhs , count );
21732183}
21742184
21752185static int
@@ -2290,8 +2300,8 @@ static _PyBinaryOpSpecializationDescr binaryop_extend_descrs[] = {
22902300 to be a freshly allocated object. */
22912301 {NB_ADD , NULL , _PyTuple_Concat , & PyTuple_Type , 0 , & PyTuple_Type , & PyTuple_Type },
22922302
2293- /* str * int / int * str: call unicode_repeat directly.
2294- unicode_repeat returns the original when n == 1. */
2303+ /* str * int / int * str: call _PyUnicode_Repeat directly.
2304+ _PyUnicode_Repeat returns the original when n == 1. */
22952305 {NB_MULTIPLY , NULL , str_int_multiply , & PyUnicode_Type , 0 , & PyUnicode_Type , & PyLong_Type },
22962306 {NB_MULTIPLY , NULL , int_str_multiply , & PyUnicode_Type , 0 , & PyLong_Type , & PyUnicode_Type },
22972307 {NB_INPLACE_MULTIPLY , NULL , str_int_multiply , & PyUnicode_Type , 0 , & PyUnicode_Type , & PyLong_Type },
@@ -2302,15 +2312,15 @@ static _PyBinaryOpSpecializationDescr binaryop_extend_descrs[] = {
23022312 {NB_ADD , NULL , _PyBytes_Concat , & PyBytes_Type , 0 , & PyBytes_Type , & PyBytes_Type },
23032313 {NB_INPLACE_ADD , NULL , _PyBytes_Concat , & PyBytes_Type , 0 , & PyBytes_Type , & PyBytes_Type },
23042314
2305- /* bytes * int / int * bytes: call bytes_repeat directly.
2306- bytes_repeat returns the original when n == 1. */
2315+ /* bytes * int / int * bytes: call _PyBytes_Repeat directly.
2316+ _PyBytes_Repeat returns the original when n == 1. */
23072317 {NB_MULTIPLY , NULL , bytes_int_multiply , & PyBytes_Type , 0 , & PyBytes_Type , & PyLong_Type },
23082318 {NB_MULTIPLY , NULL , int_bytes_multiply , & PyBytes_Type , 0 , & PyLong_Type , & PyBytes_Type },
23092319 {NB_INPLACE_MULTIPLY , NULL , bytes_int_multiply , & PyBytes_Type , 0 , & PyBytes_Type , & PyLong_Type },
23102320 {NB_INPLACE_MULTIPLY , NULL , int_bytes_multiply , & PyBytes_Type , 0 , & PyLong_Type , & PyBytes_Type },
23112321
2312- /* tuple * int / int * tuple: call tuple_repeat directly.
2313- tuple_repeat returns the original when n == 1. */
2322+ /* tuple * int / int * tuple: call _PyTuple_Repeat directly.
2323+ _PyTuple_Repeat returns the original when n == 1. */
23142324 {NB_MULTIPLY , NULL , tuple_int_multiply , & PyTuple_Type , 0 , & PyTuple_Type , & PyLong_Type },
23152325 {NB_MULTIPLY , NULL , int_tuple_multiply , & PyTuple_Type , 0 , & PyLong_Type , & PyTuple_Type },
23162326 {NB_INPLACE_MULTIPLY , NULL , tuple_int_multiply , & PyTuple_Type , 0 , & PyTuple_Type , & PyLong_Type },
0 commit comments