summaryrefslogtreecommitdiffstats
path: root/Objects/bytesobject.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-10-09 10:38:53 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-10-09 10:38:53 (GMT)
commitad7715891e3c6c51b4860e0d496843ee5417206b (patch)
treea3680f453a11828c92fa879095e5198b52764920 /Objects/bytesobject.c
parent53926a1ce2772ea5dc1c4fb8c19f5f9ae461750d (diff)
downloadcpython-ad7715891e3c6c51b4860e0d496843ee5417206b.zip
cpython-ad7715891e3c6c51b4860e0d496843ee5417206b.tar.gz
cpython-ad7715891e3c6c51b4860e0d496843ee5417206b.tar.bz2
_PyBytesWriter: simplify code to avoid "prealloc" parameters
Substract preallocate bytes from min_size before calling _PyBytesWriter_Prepare().
Diffstat (limited to 'Objects/bytesobject.c')
-rw-r--r--Objects/bytesobject.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index 4a0735f..075edf8 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -411,8 +411,7 @@ getnextarg(PyObject *args, Py_ssize_t arglen, Py_ssize_t *p_argidx)
static char*
formatfloat(PyObject *v, int flags, int prec, int type,
- PyObject **p_result, _PyBytesWriter *writer, char *str,
- Py_ssize_t prealloc)
+ PyObject **p_result, _PyBytesWriter *writer, char *str)
{
char *p;
PyObject *result;
@@ -437,11 +436,9 @@ formatfloat(PyObject *v, int flags, int prec, int type,
len = strlen(p);
if (writer != NULL) {
- if ((Py_ssize_t)len > prealloc) {
- str = _PyBytesWriter_Prepare(writer, str, len - prealloc);
- if (str == NULL)
- return NULL;
- }
+ str = _PyBytesWriter_Prepare(writer, str, len);
+ if (str == NULL)
+ return NULL;
Py_MEMCPY(str, p, len);
str += len;
return str;
@@ -865,13 +862,14 @@ _PyBytes_Format(PyObject *format, PyObject *args)
&& !(flags & (F_SIGN | F_BLANK)))
{
/* Fast path */
- res = formatfloat(v, flags, prec, c, NULL, &writer, res, 1);
+ writer.min_size -= 2; /* size preallocated by "%f" */
+ res = formatfloat(v, flags, prec, c, NULL, &writer, res);
if (res == NULL)
goto error;
continue;
}
- if (!formatfloat(v, flags, prec, c, &temp, NULL, res, 1))
+ if (!formatfloat(v, flags, prec, c, &temp, NULL, res))
goto error;
pbuf = PyBytes_AS_STRING(temp);
len = PyBytes_GET_SIZE(temp);