diff options
author | INADA Naoki <methane@users.noreply.github.com> | 2017-10-05 08:19:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-05 08:19:26 (GMT) |
commit | c1c47c166b1012d34f2c6e111ee9ccb5c4d12de7 (patch) | |
tree | 8abd62a2c34b8c1d6c9aa37b0ab47e216162edcf /Lib/re.py | |
parent | af810b35b494ef1d255d4bf340b92a9dad446995 (diff) | |
download | cpython-c1c47c166b1012d34f2c6e111ee9ccb5c4d12de7.zip cpython-c1c47c166b1012d34f2c6e111ee9ccb5c4d12de7.tar.gz cpython-c1c47c166b1012d34f2c6e111ee9ccb5c4d12de7.tar.bz2 |
bpo-31671: re: Convert RegexFlag to int before compile (GH-3862)
sre_compile does bit test (e.g. `flags & SRE_FLAG_IGNORECASE`) in loop.
`IntFlag.__and__` and `IntFlag.__new__` made it slower.
So this commit convert it to normal int before passing flags to `sre_compile()`.
Diffstat (limited to 'Lib/re.py')
-rw-r--r-- | Lib/re.py | 4 |
1 files changed, 4 insertions, 0 deletions
@@ -275,6 +275,8 @@ _cache = OrderedDict() _MAXCACHE = 512 def _compile(pattern, flags): # internal: compile pattern + if isinstance(flags, RegexFlag): + flags = flags.value try: return _cache[type(pattern), pattern, flags] except KeyError: @@ -331,6 +333,8 @@ copyreg.pickle(Pattern, _pickle, _compile) class Scanner: def __init__(self, lexicon, flags=0): from sre_constants import BRANCH, SUBPATTERN + if isinstance(flags, RegexFlag): + flags = flags.value self.lexicon = lexicon # combine phrases into a compound pattern p = [] |