Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,10 @@ list_repr_impl(PyListObject *v)
so must refetch the list size on each iteration. */
for (Py_ssize_t i = 0; i < Py_SIZE(v); ++i) {
if (i > 0) {
if (PyUnicodeWriter_WriteUTF8(writer, ", ", 2) < 0) {
if (PyUnicodeWriter_WriteChar(writer, ',') < 0) {
goto error;
}
if (PyUnicodeWriter_WriteChar(writer, ' ') < 0) {
goto error;
}
}
Expand All @@ -560,9 +563,7 @@ list_repr_impl(PyListObject *v)
return PyUnicodeWriter_Finish(writer);

error:
if (writer != NULL) {
PyUnicodeWriter_Discard(writer);
}
PyUnicodeWriter_Discard(writer);
Py_ReprLeave((PyObject *)v);
return NULL;
}
Expand Down
3 changes: 3 additions & 0 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -13428,6 +13428,9 @@ PyUnicodeWriter_Create(Py_ssize_t length)

void PyUnicodeWriter_Discard(PyUnicodeWriter *writer)
{
if (writer == NULL) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be documented. Please do this in a separate PR.

Also, I think it is worth to try to optimize PyUnicodeWriter_WriteUTF8() for short ASCII strings.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be documented. Please do this in a separate PR.

Oh ok. I reverted the change.

return;
}
_PyUnicodeWriter_Dealloc((_PyUnicodeWriter*)writer);
PyMem_Free(writer);
}
Expand Down
Loading