diff options
| author | Christian Heimes <christian@cheimes.de> | 2008-01-30 11:32:37 +0000 |
|---|---|---|
| committer | Christian Heimes <christian@cheimes.de> | 2008-01-30 11:32:37 +0000 |
| commit | 4c6c96c00e6855e91f47ea1996a3aea84cc4375a (patch) | |
| tree | 1b09704c79f6a2e7031a4c58b02d055dfd284cdf /Include/unicodeobject.h | |
| parent | 16a5e777a7d836bbf0e94db643c04498747c7f48 (diff) | |
| download | cpython-4c6c96c00e6855e91f47ea1996a3aea84cc4375a.tar.gz | |
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()
Diffstat (limited to 'Include/unicodeobject.h')
| -rw-r--r-- | Include/unicodeobject.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h index 2c11bfd452..8809b342b6 100644 --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -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) |
