@@ -360,13 +360,6 @@ _build_rval_index_tuple(PyObject *rval, Py_ssize_t idx) {
360360 return tpl ;
361361}
362362
363- static inline int
364- _PyUnicodeWriter_IsEmpty (PyUnicodeWriter * writer_pub )
365- {
366- _PyUnicodeWriter * writer = (_PyUnicodeWriter * )writer_pub ;
367- return (writer -> pos == 0 );
368- }
369-
370363static PyObject *
371364scanstring_unicode (PyObject * pystr , Py_ssize_t end , int strict , Py_ssize_t * next_end_ptr )
372365{
@@ -385,10 +378,7 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next
385378 const void * buf ;
386379 int kind ;
387380
388- PyUnicodeWriter * writer = PyUnicodeWriter_Create (0 );
389- if (writer == NULL ) {
390- goto bail ;
391- }
381+ PyUnicodeWriter * writer = NULL ;
392382
393383 len = PyUnicode_GET_LENGTH (pystr );
394384 buf = PyUnicode_DATA (pystr );
@@ -419,19 +409,23 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next
419409
420410 if (c == '"' ) {
421411 // Fast path for simple case.
422- if (_PyUnicodeWriter_IsEmpty ( writer ) ) {
412+ if (writer == NULL ) {
423413 PyObject * ret = PyUnicode_Substring (pystr , end , next );
424414 if (ret == NULL ) {
425415 goto bail ;
426416 }
427- PyUnicodeWriter_Discard (writer );
428417 * next_end_ptr = next + 1 ;;
429418 return ret ;
430419 }
431420 }
432421 else if (c != '\\' ) {
433422 raise_errmsg ("Unterminated string starting at" , pystr , begin );
434423 goto bail ;
424+ } else if (writer == NULL ) {
425+ writer = PyUnicodeWriter_Create (0 );
426+ if (writer == NULL ) {
427+ goto bail ;
428+ }
435429 }
436430
437431 /* Pick up this chunk if it's not zero length */
0 commit comments