Skip to content

bpo-34636: Use fast path for more chars in SRE category macros. #9170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Speed up re scanning of many non-matching characters for \s \w and \d within
bytes objects. (microoptimization)
6 changes: 3 additions & 3 deletions Modules/_sre.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ static const char copyright[] =
/* search engine state */

#define SRE_IS_DIGIT(ch)\
((ch) < 128 && Py_ISDIGIT(ch))
((ch) <= '9' && Py_ISDIGIT(ch))
#define SRE_IS_SPACE(ch)\
((ch) < 128 && Py_ISSPACE(ch))
((ch) <= ' ' && Py_ISSPACE(ch))
#define SRE_IS_LINEBREAK(ch)\
((ch) == '\n')
#define SRE_IS_WORD(ch)\
((ch) < 128 && (Py_ISALNUM(ch) || (ch) == '_'))
((ch) <= 'z' && (Py_ISALNUM(ch) || (ch) == '_'))

static unsigned int sre_lower_ascii(unsigned int ch)
{
Expand Down