mirror of
https://github.com/python/cpython.git
synced 2025-09-15 05:06:12 +00:00
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:
parent
7d5fbaee42
commit
4d4f270941
3 changed files with 92 additions and 19 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue