summaryrefslogtreecommitdiffstats
path: root/Modules/itertoolsmodule.c
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2007-05-19 21:49:49 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2007-05-19 21:49:49 (GMT)
commit7569dfe11d51a11bfb11002d31245b889916fb11 (patch)
tree7e4cbbb7a27a366ea0cdc8eeacc05a23f649e4cd /Modules/itertoolsmodule.c
parent94b59bb14474b6fe5a272a2c60b65f8375e827b3 (diff)
downloadcpython-7569dfe11d51a11bfb11002d31245b889916fb11.zip
cpython-7569dfe11d51a11bfb11002d31245b889916fb11.tar.gz
cpython-7569dfe11d51a11bfb11002d31245b889916fb11.tar.bz2
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 'Modules/itertoolsmodule.c')
-rw-r--r--Modules/itertoolsmodule.c14
1 files changed, 2 insertions, 12 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index c3f198e..2685ca4 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -2389,20 +2389,10 @@ repeat_next(repeatobject *ro)
static PyObject *
repeat_repr(repeatobject *ro)
{
- PyObject *result, *objrepr;
-
- objrepr = PyObject_Repr(ro->element);
- if (objrepr == NULL)
- return NULL;
-
if (ro->cnt == -1)
- result = PyUnicode_FromFormat("repeat(%U)",
- objrepr);
+ return PyUnicode_FromFormat("repeat(%R)", ro->element);
else
- result = PyUnicode_FromFormat("repeat(%U, %zd)",
- objrepr, ro->cnt);
- Py_DECREF(objrepr);
- return result;
+ return PyUnicode_FromFormat("repeat(%R, %zd)", ro->element, ro->cnt);
}
static PyObject *