[Python-checkins] cpython: Ensure that 1-char singletons get used
antoine.pitrou
python-checkins at python.org
Thu Oct 6 22:13:02 CEST 2011
http://hg.python.org/cpython/rev/d3d7ec004af0
changeset: 72762:d3d7ec004af0
user: Antoine Pitrou <solipsis at pitrou.net>
date: Thu Oct 06 22:07:51 2011 +0200
summary:
Ensure that 1-char singletons get used
files:
Objects/unicodeobject.c | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -1622,6 +1622,8 @@
assert(*p < 128);
}
#endif
+ if (size == 1)
+ return get_latin1_char(s[0]);
res = PyUnicode_New(size, 127);
if (!res)
return NULL;
@@ -1653,6 +1655,8 @@
Py_ssize_t i;
assert(size >= 0);
+ if (size == 1)
+ return get_latin1_char(u[0]);
for (i = 0; i < size; i++) {
if (u[i] & 0x80) {
max_char = 255;
@@ -1675,6 +1679,8 @@
Py_ssize_t i;
assert(size >= 0);
+ if (size == 1 && u[0] < 256)
+ return get_latin1_char(u[0]);
for (i = 0; i < size; i++) {
if (u[i] > max_char) {
max_char = u[i];
@@ -1702,6 +1708,8 @@
Py_ssize_t i;
assert(size >= 0);
+ if (size == 1 && u[0] < 256)
+ return get_latin1_char(u[0]);
for (i = 0; i < size; i++) {
if (u[i] > max_char) {
max_char = u[i];
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list