@@ -228,41 +228,6 @@ template_iter(PyObject *op)
228228 return (PyObject * )iter ;
229229}
230230
231- static PyObject *
232- template_interpolations_copy (PyObject * interpolations ) {
233- Py_ssize_t interpolationslen = PyTuple_GET_SIZE (interpolations );
234- PyObject * newinterpolations = PyTuple_New (interpolationslen );
235- if (!newinterpolations ) {
236- return NULL ;
237- }
238-
239- for (Py_ssize_t i = 0 ; i < interpolationslen ; i ++ ) {
240- PyTuple_SET_ITEM (newinterpolations , i , Py_NewRef (PyTuple_GET_ITEM (interpolations , i )));
241- }
242- return newinterpolations ;
243- }
244-
245- static PyObject *
246- template_interpolations_concat (PyObject * left , PyObject * right ) {
247- Py_ssize_t leftlen = PyTuple_GET_SIZE (left );
248- Py_ssize_t rightlen = PyTuple_GET_SIZE (right );
249- Py_ssize_t interpolationslen = leftlen + rightlen ;
250-
251- PyObject * newinterpolations = PyTuple_New (interpolationslen );
252- if (!newinterpolations ) {
253- return NULL ;
254- }
255-
256- Py_ssize_t index = 0 ;
257- for (Py_ssize_t i = 0 ; i < leftlen ; i ++ ) {
258- PyTuple_SET_ITEM (newinterpolations , index ++ , Py_NewRef (PyTuple_GET_ITEM (left , i )));
259- }
260- for (Py_ssize_t i = 0 ; i < rightlen ; i ++ ) {
261- PyTuple_SET_ITEM (newinterpolations , index ++ , Py_NewRef (PyTuple_GET_ITEM (right , i )));
262- }
263- return newinterpolations ;
264- }
265-
266231static PyObject *
267232template_strings_append_str (PyObject * strings , PyObject * str )
268233{
@@ -350,7 +315,7 @@ template_concat_templates(templateobject *self, templateobject *other)
350315 return NULL ;
351316 }
352317
353- PyObject * newinterpolations = template_interpolations_concat (self -> interpolations , other -> interpolations );
318+ PyObject * newinterpolations = PySequence_Concat (self -> interpolations , other -> interpolations );
354319 if (newinterpolations == NULL ) {
355320 Py_DECREF (newstrings );
356321 return NULL ;
@@ -370,15 +335,8 @@ template_concat_template_str(templateobject *self, PyObject *other)
370335 return NULL ;
371336 }
372337
373- PyObject * newinterpolations = template_interpolations_copy (self -> interpolations );
374- if (newinterpolations == NULL ) {
375- Py_DECREF (newstrings );
376- return NULL ;
377- }
378-
379- templateobject * newtemplate = template_from_strings_interpolations (Py_TYPE (self ), newstrings , newinterpolations );
338+ templateobject * newtemplate = template_from_strings_interpolations (Py_TYPE (self ), newstrings , self -> interpolations );
380339 Py_DECREF (newstrings );
381- Py_DECREF (newinterpolations );
382340 return (PyObject * ) newtemplate ;
383341}
384342
@@ -390,15 +348,8 @@ template_concat_str_template(templateobject *self, PyObject *other)
390348 return NULL ;
391349 }
392350
393- PyObject * newinterpolations = template_interpolations_copy (self -> interpolations );
394- if (newinterpolations == NULL ) {
395- Py_DECREF (newstrings );
396- return NULL ;
397- }
398-
399- templateobject * newtemplate = template_from_strings_interpolations (Py_TYPE (self ), newstrings , newinterpolations );
351+ templateobject * newtemplate = template_from_strings_interpolations (Py_TYPE (self ), newstrings , self -> interpolations );
400352 Py_DECREF (newstrings );
401- Py_DECREF (newinterpolations );
402353 return (PyObject * ) newtemplate ;
403354}
404355
0 commit comments