summaryrefslogtreecommitdiff
path: root/Objects/sliceobject.c
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2007-05-19 21:49:49 +0000
committerWalter Dörwald <walter@livinglogic.de>2007-05-19 21:49:49 +0000
commita86681cd11d43767fa468e072e539bd54c70c7cd (patch)
tree2bcfc980b96c5d920d7e2a4205a69478fcd13295 /Objects/sliceobject.c
parent179c9be79740521e70ce840907b85aab0b6b3191 (diff)
downloadcpython-a86681cd11d43767fa468e072e539bd54c70c7cd.tar.gz
Add a format specifier %R to PyUnicode_FromFormat(), which embeds
the result of a call to PyObject_Repr() into the string. This makes it possible to simplify many repr implementations. PyUnicode_FromFormat() uses two steps to create the final string: A first pass through the format string determines the size of the final string and a second pass creates the string. To avoid calling PyObject_Repr() twice for each %R specifier, PyObject_Repr() is called during the size calculation step and the results are stored in an array (whose size is determined at the start by counting %R specifiers).
Diffstat (limited to 'Objects/sliceobject.c')
-rw-r--r--Objects/sliceobject.c13
1 files changed, 1 insertions, 12 deletions
diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c
index d526a079db..a30edefb46 100644
--- a/Objects/sliceobject.c
+++ b/Objects/sliceobject.c
@@ -226,18 +226,7 @@ slice_dealloc(PySliceObject *r)
static PyObject *
slice_repr(PySliceObject *r)
{
- PyObject *s, *comma;
-
- s = PyUnicode_FromString("slice(");
- comma = PyUnicode_FromString(", ");
- PyUnicode_AppendAndDel(&s, PyObject_Repr(r->start));
- PyUnicode_Append(&s, comma);
- PyUnicode_AppendAndDel(&s, PyObject_Repr(r->stop));
- PyUnicode_Append(&s, comma);
- PyUnicode_AppendAndDel(&s, PyObject_Repr(r->step));
- PyUnicode_AppendAndDel(&s, PyUnicode_FromString(")"));
- Py_DECREF(comma);
- return s;
+ return PyUnicode_FromFormat("slice(%R, %R, %R)", r->start, r->stop, r->step);
}
static PyMemberDef slice_members[] = {