[issue13155] Optimize finding the max character width

STINNER Victor report at bugs.python.org
Wed Oct 12 02:11:45 CEST 2011


STINNER Victor <victor.stinner at haypocalc.com> added the comment:

> Ok, updated patch.

"ret = ~mask + 1;" looks wrong: (~0xFFFFFF80+1) gives 128, not 127. I don't see why you need:

+    if (ret < 128)
+        return 127;
+    if (ret < 256)
+        return 255;

#undef ASCII_CHAR_MASK should be #undef UCS1_ASCII_CHAR_MASK


#error Invalid STRINGLIB_SIZEOF_CHAR (must be 1, 2 or 4)
should be
#error Invalid STRINGLIB_SIZEOF_CHAR (must be 2 or 4)

Why do you need these forward declarations? It's maybe related to another patch?

 static PyObject *
+unicode_fromascii(const unsigned char *s, Py_ssize_t size);
+static PyObject *
+_PyUnicode_FromUCS1(const unsigned char *s, Py_ssize_t size);
+static PyObject *
+_PyUnicode_FromUCS2(const Py_UCS2 *s, Py_ssize_t size);
+static PyObject *
+_PyUnicode_FromUCS4(const Py_UCS4 *s, Py_ssize_t size);

(You kept Py_UCS4 for "Py_UCS4 bits", but Py_UCS4 is maybe just fine.)

By the way, your function rocks :-) Use bit masks is a great idea, especially your "bits = p[0] | p[1] | p[2] | p[3]" "hack".

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13155>
_______________________________________


More information about the Python-bugs-list mailing list