diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-10-03 18:06:05 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-10-03 18:06:05 (GMT) |
commit | 77bb47b3125d271408642505cbc4edd074eb7f1c (patch) | |
tree | d077ac0a9e5d17ca2e664a735b92ba2743662021 | |
parent | 8619cd7376a3614946c41caca9b01948ebac084e (diff) | |
download | cpython-77bb47b3125d271408642505cbc4edd074eb7f1c.zip cpython-77bb47b3125d271408642505cbc4edd074eb7f1c.tar.gz cpython-77bb47b3125d271408642505cbc4edd074eb7f1c.tar.bz2 |
Simplify unicode_resizable(): singletons reference count is at least 2
-rw-r--r-- | Objects/unicodeobject.c | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 1d90f69..46332fb 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1257,26 +1257,20 @@ unicode_dealloc(register PyUnicodeObject *unicode) static int unicode_resizable(PyObject *unicode) { - Py_ssize_t len; if (Py_REFCNT(unicode) != 1) return 0; if (PyUnicode_CHECK_INTERNED(unicode)) return 0; - if (unicode == unicode_empty) - return 0; - if (_PyUnicode_KIND(unicode) == PyUnicode_WCHAR_KIND) - len = PyUnicode_WSTR_LENGTH(unicode); - else - len = PyUnicode_GET_LENGTH(unicode); - if (len == 1) { - Py_UCS4 ch; - if (_PyUnicode_KIND(unicode) == PyUnicode_WCHAR_KIND) - ch = _PyUnicode_WSTR(unicode)[0]; - else - ch = PyUnicode_READ_CHAR(unicode, 0); + assert (unicode != unicode_empty); +#ifdef Py_DEBUG + if (_PyUnicode_KIND(unicode) != PyUnicode_WCHAR_KIND + && PyUnicode_GET_LENGTH(unicode) == 1) + { + Py_UCS4 ch = PyUnicode_READ_CHAR(unicode, 0); if (ch < 256 && unicode_latin1[ch] == unicode) return 0; } +#endif return 1; } |