Patch #1970 by Antoine Pitrou: Speedup unicode whitespace and linebreak detection. The speedup is about 25% for split() (571 / 457 usec) and 35% (175 / 127 usec )for splitlines()

This commit is contained in:
Christian Heimes 2008-01-30 11:32:37 +00:00
parent 7d5fbaee42
commit 4d4f270941
3 changed files with 92 additions and 19 deletions

View file

@ -348,7 +348,14 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
#else
#define Py_UNICODE_ISSPACE(ch) _PyUnicode_IsWhitespace(ch)
/* Since splitting on whitespace is an important use case, and whitespace
in most situations is solely ASCII whitespace, we optimize for the common
case by using a quick look-up table with an inlined check.
*/
extern const unsigned char _Py_ascii_whitespace[];
#define Py_UNICODE_ISSPACE(ch) \
((ch) < 128U ? _Py_ascii_whitespace[(ch)] : _PyUnicode_IsWhitespace(ch))
#define Py_UNICODE_ISLOWER(ch) _PyUnicode_IsLowercase(ch)
#define Py_UNICODE_ISUPPER(ch) _PyUnicode_IsUppercase(ch)