[Python-checkins] cpython: Issue #28400: Removed uncessary checks in unicode_char and resize_copy.
serhiy.storchaka
python-checkins at python.org
Sun Oct 9 16:45:08 EDT 2016
https://hg.python.org/cpython/rev/61e454a1c9d7
changeset: 104425:61e454a1c9d7
user: Serhiy Storchaka <storchaka at gmail.com>
date: Sun Oct 09 23:44:48 2016 +0300
summary:
Issue #28400: Removed uncessary checks in unicode_char and resize_copy.
1. In resize_copy we don't need to PyUnicode_READY(unicode) since when
it's not PyUnicode_WCHAR_KIND it should be ready.
2. In unicode_char, PyUnicode_1BYTE_KIND is handled by get_latin1_char.
Patch by Xiang Zhang.
files:
Objects/unicodeobject.c | 14 +++++---------
1 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -1029,8 +1029,7 @@
if (_PyUnicode_KIND(unicode) != PyUnicode_WCHAR_KIND) {
PyObject *copy;
- if (PyUnicode_READY(unicode) == -1)
- return NULL;
+ assert(PyUnicode_IS_READY(unicode));
copy = PyUnicode_New(length, PyUnicode_MAX_CHAR_VALUE(unicode));
if (copy == NULL)
@@ -1974,14 +1973,11 @@
unicode = PyUnicode_New(1, ch);
if (unicode == NULL)
return NULL;
- switch (PyUnicode_KIND(unicode)) {
- case PyUnicode_1BYTE_KIND:
- PyUnicode_1BYTE_DATA(unicode)[0] = (Py_UCS1)ch;
- break;
- case PyUnicode_2BYTE_KIND:
+
+ assert(PyUnicode_KIND(unicode) != PyUnicode_1BYTE_KIND);
+ if (PyUnicode_KIND(unicode) == PyUnicode_2BYTE_KIND) {
PyUnicode_2BYTE_DATA(unicode)[0] = (Py_UCS2)ch;
- break;
- default:
+ } else {
assert(PyUnicode_KIND(unicode) == PyUnicode_4BYTE_KIND);
PyUnicode_4BYTE_DATA(unicode)[0] = ch;
}
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list