[Python-checkins] python/dist/src/Lib sre_parse.py, 1.63, 1.64 sre_compile.py, 1.56, 1.57

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Mon Feb 28 20:27:55 CET 2005


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12064

Modified Files:
	sre_parse.py sre_compile.py 
Log Message:
Complete the previous effort to factor out constant expressions
and improve the speed of the if/elif/else blocks.



Index: sre_parse.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre_parse.py,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -d -r1.63 -r1.64
--- sre_parse.py	3 Sep 2004 20:15:56 -0000	1.63
+++ sre_parse.py	28 Feb 2005 19:27:52 -0000	1.64
@@ -16,15 +16,21 @@
 
 from sre_constants import *
 
+def set(seq):
+    s = {}
+    for elem in seq:
+        s[elem] = 1
+    return s
+
 SPECIAL_CHARS = ".\\[{()*+?^$|"
 REPEAT_CHARS = "*+?{"
 
-DIGITS = tuple("0123456789")
+DIGITS = set("0123456789")
 
-OCTDIGITS = tuple("01234567")
-HEXDIGITS = tuple("0123456789abcdefABCDEF")
+OCTDIGITS = set("01234567")
+HEXDIGITS = set("0123456789abcdefABCDEF")
 
-WHITESPACE = tuple(" \t\n\r\v\f")
+WHITESPACE = set(" \t\n\r\v\f")
 
 ESCAPES = {
     r"\a": (LITERAL, ord("\a")),
@@ -371,6 +377,11 @@
     subpattern.append((GROUPREF_EXISTS, (condgroup, item_yes, item_no)))
     return subpattern
 
+_PATTERNENDERS = set("|)")
+_ASSERTCHARS = set("=!<")
+_LOOKBEHINDASSERTCHARS = set("=!")
+_REPEATCODES = set([MIN_REPEAT, MAX_REPEAT])
+
 def _parse(source, state):
     # parse a simple pattern
     subpattern = SubPattern(state)
@@ -380,10 +391,10 @@
     sourceget = source.get
     sourcematch = source.match
     _len = len
-    PATTERNENDERS = ("|", ")")
-    ASSERTCHARS = ("=", "!", "<")
-    LOOKBEHINDASSERTCHARS = ("=", "!")
-    REPEATCODES = (MIN_REPEAT, MAX_REPEAT)
+    PATTERNENDERS = _PATTERNENDERS
+    ASSERTCHARS = _ASSERTCHARS
+    LOOKBEHINDASSERTCHARS = _LOOKBEHINDASSERTCHARS
+    REPEATCODES = _REPEATCODES
 
     while 1:
 

Index: sre_compile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre_compile.py,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- sre_compile.py	15 Oct 2004 06:15:08 -0000	1.56
+++ sre_compile.py	28 Feb 2005 19:27:52 -0000	1.57
@@ -24,14 +24,25 @@
 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:



More information about the Python-checkins mailing list