summaryrefslogtreecommitdiffstats
path: root/Lib/sre_compile.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2005-02-28 19:27:52 (GMT)
committerRaymond Hettinger <python@rcn.com>2005-02-28 19:27:52 (GMT)
commit049ade2997aee8cd6564e05d29dbe0b390ebf27b (patch)
tree986f3e9f04a722e98cbd8cfb3f501531834898a1 /Lib/sre_compile.py
parent9533e3402433245489bcf55adf1e134ca71b4798 (diff)
downloadcpython-049ade2997aee8cd6564e05d29dbe0b390ebf27b.zip
cpython-049ade2997aee8cd6564e05d29dbe0b390ebf27b.tar.gz
cpython-049ade2997aee8cd6564e05d29dbe0b390ebf27b.tar.bz2
Complete the previous effort to factor out constant expressions
and improve the speed of the if/elif/else blocks.
Diffstat (limited to 'Lib/sre_compile.py')
-rw-r--r--Lib/sre_compile.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/Lib/sre_compile.py b/Lib/sre_compile.py
index 27ab1fe..d3eb3c1 100644
--- a/Lib/sre_compile.py
+++ b/Lib/sre_compile.py
@@ -24,14 +24,25 @@ else:
def _identityfunction(x):
return x
+def set(seq):
+ s = {}
+ for elem in seq:
+ s[elem] = 1
+ return s
+
+_LITERAL_CODES = set([LITERAL, NOT_LITERAL])
+_REPEATING_CODES = set([REPEAT, MIN_REPEAT, MAX_REPEAT])
+_SUCCESS_CODES = set([SUCCESS, FAILURE])
+_ASSERT_CODES = set([ASSERT, ASSERT_NOT])
+
def _compile(code, pattern, flags):
# internal: compile a (sub)pattern
emit = code.append
_len = len
- LITERAL_CODES = {LITERAL:1, NOT_LITERAL:1}
- REPEATING_CODES = {REPEAT:1, MIN_REPEAT:1, MAX_REPEAT:1}
- SUCCESS_CODES = {SUCCESS:1, FAILURE:1}
- ASSERT_CODES = {ASSERT:1, ASSERT_NOT:1}
+ LITERAL_CODES = _LITERAL_CODES
+ REPEATING_CODES = _REPEATING_CODES
+ SUCCESS_CODES = _SUCCESS_CODES
+ ASSERT_CODES = _ASSERT_CODES
for op, av in pattern:
if op in LITERAL_CODES:
if flags & SRE_FLAG_IGNORECASE: