@@ -360,13 +360,6 @@ _build_rval_index_tuple(PyObject *rval, Py_ssize_t idx) {
360
360
return tpl ;
361
361
}
362
362
363
- static inline int
364
- _PyUnicodeWriter_IsEmpty (PyUnicodeWriter * writer_pub )
365
- {
366
- _PyUnicodeWriter * writer = (_PyUnicodeWriter * )writer_pub ;
367
- return (writer -> pos == 0 );
368
- }
369
-
370
363
static PyObject *
371
364
scanstring_unicode (PyObject * pystr , Py_ssize_t end , int strict , Py_ssize_t * next_end_ptr )
372
365
{
@@ -385,10 +378,7 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next
385
378
const void * buf ;
386
379
int kind ;
387
380
388
- PyUnicodeWriter * writer = PyUnicodeWriter_Create (0 );
389
- if (writer == NULL ) {
390
- goto bail ;
391
- }
381
+ PyUnicodeWriter * writer = NULL ;
392
382
393
383
len = PyUnicode_GET_LENGTH (pystr );
394
384
buf = PyUnicode_DATA (pystr );
@@ -419,19 +409,23 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next
419
409
420
410
if (c == '"' ) {
421
411
// Fast path for simple case.
422
- if (_PyUnicodeWriter_IsEmpty ( writer ) ) {
412
+ if (writer == NULL ) {
423
413
PyObject * ret = PyUnicode_Substring (pystr , end , next );
424
414
if (ret == NULL ) {
425
415
goto bail ;
426
416
}
427
- PyUnicodeWriter_Discard (writer );
428
417
* next_end_ptr = next + 1 ;;
429
418
return ret ;
430
419
}
431
420
}
432
421
else if (c != '\\' ) {
433
422
raise_errmsg ("Unterminated string starting at" , pystr , begin );
434
423
goto bail ;
424
+ } else if (writer == NULL ) {
425
+ writer = PyUnicodeWriter_Create (0 );
426
+ if (writer == NULL ) {
427
+ goto bail ;
428
+ }
435
429
}
436
430
437
431
/* Pick up this chunk if it's not zero length */
0 commit comments