summaryrefslogtreecommitdiffstats
path: root/Objects/stringlib
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-10-09 10:57:22 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-10-09 10:57:22 (GMT)
commitce179bf6baed91ba84cc3ff647e96287c3b8e2f2 (patch)
tree47ccc59059e1b2565784bbaf8c9c778a39628cfa /Objects/stringlib
parentad7715891e3c6c51b4860e0d496843ee5417206b (diff)
downloadcpython-ce179bf6baed91ba84cc3ff647e96287c3b8e2f2.zip
cpython-ce179bf6baed91ba84cc3ff647e96287c3b8e2f2.tar.gz
cpython-ce179bf6baed91ba84cc3ff647e96287c3b8e2f2.tar.bz2
Add _PyBytesWriter_WriteBytes() to factorize the code
Diffstat (limited to 'Objects/stringlib')
-rw-r--r--Objects/stringlib/codecs.h22
1 files changed, 11 insertions, 11 deletions
diff --git a/Objects/stringlib/codecs.h b/Objects/stringlib/codecs.h
index 6842f67..7e8d928 100644
--- a/Objects/stringlib/codecs.h
+++ b/Objects/stringlib/codecs.h
@@ -388,24 +388,24 @@ STRINGLIB(utf8_encoder)(PyObject *unicode,
/* substract preallocated bytes */
writer.min_size -= max_char_size;
- if (PyBytes_Check(rep))
- repsize = PyBytes_GET_SIZE(rep);
- else
- repsize = PyUnicode_GET_LENGTH(rep);
-
- p = _PyBytesWriter_Prepare(&writer, p, repsize);
- if (p == NULL)
- goto error;
-
if (PyBytes_Check(rep)) {
- memcpy(p, PyBytes_AS_STRING(rep), repsize);
- p += repsize;
+ p = _PyBytesWriter_WriteBytes(&writer, p,
+ PyBytes_AS_STRING(rep),
+ PyBytes_GET_SIZE(rep));
+ if (p == NULL)
+ goto error;
}
else {
/* rep is unicode */
if (PyUnicode_READY(rep) < 0)
goto error;
+ repsize = PyUnicode_GET_LENGTH(rep);
+
+ p = _PyBytesWriter_Prepare(&writer, p, repsize);
+ if (p == NULL)
+ goto error;
+
if (!PyUnicode_IS_ASCII(rep)) {
raise_encode_exception(&exc, "utf-8",
unicode,