[Python-checkins] cpython (merge 3.6 -> default): Issue #28561: Clean up UTF-8 encoder: remove dead code, update comments, etc.
serhiy.storchaka
python-checkins at python.org
Sun Oct 30 12:26:15 EDT 2016
https://hg.python.org/cpython/rev/ee3670d9bda6
changeset: 104821:ee3670d9bda6
parent: 104819:d48de4152b59
parent: 104820:542065b03c10
user: Serhiy Storchaka <storchaka at gmail.com>
date: Sun Oct 30 18:25:46 2016 +0200
summary:
Issue #28561: Clean up UTF-8 encoder: remove dead code, update comments, etc.
Patch by Xiang Zhang.
files:
Objects/stringlib/codecs.h | 14 ++++----------
1 files changed, 4 insertions(+), 10 deletions(-)
diff --git a/Objects/stringlib/codecs.h b/Objects/stringlib/codecs.h
--- a/Objects/stringlib/codecs.h
+++ b/Objects/stringlib/codecs.h
@@ -262,9 +262,7 @@
Py_ssize_t size,
const char *errors)
{
-#define MAX_SHORT_UNICHARS 300 /* largest size we'll do on the stack */
-
- Py_ssize_t i; /* index into s of next input byte */
+ Py_ssize_t i; /* index into data of next input character */
char *p; /* next free byte in output buffer */
#if STRINGLIB_SIZEOF_CHAR > 1
PyObject *error_handler_obj = NULL;
@@ -389,7 +387,7 @@
goto error;
/* subtract preallocated bytes */
- writer.min_size -= max_char_size;
+ writer.min_size -= max_char_size * (newpos - startpos);
if (PyBytes_Check(rep)) {
p = _PyBytesWriter_WriteBytes(&writer, p,
@@ -402,14 +400,12 @@
goto error;
if (!PyUnicode_IS_ASCII(rep)) {
- raise_encode_exception(&exc, "utf-8",
- unicode,
- i-1, i,
+ raise_encode_exception(&exc, "utf-8", unicode,
+ startpos, endpos,
"surrogates not allowed");
goto error;
}
- assert(PyUnicode_KIND(rep) == PyUnicode_1BYTE_KIND);
p = _PyBytesWriter_WriteBytes(&writer, p,
PyUnicode_DATA(rep),
PyUnicode_GET_LENGTH(rep));
@@ -463,8 +459,6 @@
_PyBytesWriter_Dealloc(&writer);
return NULL;
#endif
-
-#undef MAX_SHORT_UNICHARS
}
/* The pattern for constructing UCS2-repeated masks. */
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list