Add _PyUnicodeWriter_WriteASCIIString() function

This commit is contained in:
Victor Stinner 2013-11-19 12:54:53 +01:00
parent 4d3f109ad3
commit 4a58707a34
4 changed files with 96 additions and 38 deletions

View file

@ -339,19 +339,12 @@ list_repr(PyListObject *v)
{
Py_ssize_t i;
PyObject *s;
static PyObject *sep = NULL;
_PyUnicodeWriter writer;
if (Py_SIZE(v) == 0) {
return PyUnicode_FromString("[]");
}
if (sep == NULL) {
sep = PyUnicode_FromString(", ");
if (sep == NULL)
return NULL;
}
i = Py_ReprEnter((PyObject*)v);
if (i != 0) {
return i > 0 ? PyUnicode_FromString("[...]") : NULL;
@ -369,7 +362,7 @@ list_repr(PyListObject *v)
so must refetch the list size on each iteration. */
for (i = 0; i < Py_SIZE(v); ++i) {
if (i > 0) {
if (_PyUnicodeWriter_WriteStr(&writer, sep) < 0)
if (_PyUnicodeWriter_WriteASCIIString(&writer, ", ", 2) < 0)
goto error;
}