@@ -9892,20 +9892,10 @@ case_operation(PyObject *self,
98929892PyObject *
98939893PyUnicode_Join (PyObject * separator , PyObject * seq )
98949894{
9895- PyObject * sep = NULL ;
9896- Py_ssize_t seplen ;
9897- PyObject * res = NULL ; /* the result */
9898- PyObject * fseq ; /* PySequence_Fast(seq) */
9899- Py_ssize_t seqlen ; /* len(fseq) -- number of items in sequence */
9895+ PyObject * res ;
9896+ PyObject * fseq ;
9897+ Py_ssize_t seqlen ;
99009898 PyObject * * items ;
9901- PyObject * item ;
9902- Py_ssize_t sz , i , res_offset ;
9903- Py_UCS4 maxchar ;
9904- Py_UCS4 item_maxchar ;
9905- int use_memcpy ;
9906- unsigned char * res_data = NULL , * sep_data = NULL ;
9907- PyObject * last_obj ;
9908- unsigned int kind = 0 ;
99099899
99109900 fseq = PySequence_Fast (seq , "can only join an iterable" );
99119901 if (fseq == NULL ) {
@@ -9916,21 +9906,39 @@ PyUnicode_Join(PyObject *separator, PyObject *seq)
99169906 * so we are sure that fseq won't be mutated.
99179907 */
99189908
9909+ items = PySequence_Fast_ITEMS (fseq );
99199910 seqlen = PySequence_Fast_GET_SIZE (fseq );
9911+ res = _PyUnicode_JoinArray (separator , items , seqlen );
9912+ Py_DECREF (fseq );
9913+ return res ;
9914+ }
9915+
9916+ PyObject *
9917+ _PyUnicode_JoinArray (PyObject * separator , PyObject * * items , Py_ssize_t seqlen )
9918+ {
9919+ PyObject * res = NULL ; /* the result */
9920+ PyObject * sep = NULL ;
9921+ Py_ssize_t seplen ;
9922+ PyObject * item ;
9923+ Py_ssize_t sz , i , res_offset ;
9924+ Py_UCS4 maxchar ;
9925+ Py_UCS4 item_maxchar ;
9926+ int use_memcpy ;
9927+ unsigned char * res_data = NULL , * sep_data = NULL ;
9928+ PyObject * last_obj ;
9929+ unsigned int kind = 0 ;
9930+
99209931 /* If empty sequence, return u"". */
99219932 if (seqlen == 0 ) {
9922- Py_DECREF (fseq );
99239933 _Py_RETURN_UNICODE_EMPTY ();
99249934 }
99259935
99269936 /* If singleton sequence with an exact Unicode, return that. */
99279937 last_obj = NULL ;
9928- items = PySequence_Fast_ITEMS (fseq );
99299938 if (seqlen == 1 ) {
99309939 if (PyUnicode_CheckExact (items [0 ])) {
99319940 res = items [0 ];
99329941 Py_INCREF (res );
9933- Py_DECREF (fseq );
99349942 return res ;
99359943 }
99369944 seplen = 0 ;
@@ -10065,13 +10073,11 @@ PyUnicode_Join(PyObject *separator, PyObject *seq)
1006510073 assert (res_offset == PyUnicode_GET_LENGTH (res ));
1006610074 }
1006710075
10068- Py_DECREF (fseq );
1006910076 Py_XDECREF (sep );
1007010077 assert (_PyUnicode_CheckConsistency (res , 1 ));
1007110078 return res ;
1007210079
1007310080 onError :
10074- Py_DECREF (fseq );
1007510081 Py_XDECREF (sep );
1007610082 Py_XDECREF (res );
1007710083 return NULL ;
0 commit comments