[Python-checkins] python/dist/src/Lib sre.py,1.51,1.52

rhettinger@users.sourceforge.net rhettinger at users.sourceforge.net
Tue Sep 13 00:50:40 CEST 2005


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

Modified Files:
	sre.py 
Log Message:
Speed-up escape()

Index: sre.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre.py,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- sre.py	24 Sep 2004 03:41:05 -0000	1.51
+++ sre.py	12 Sep 2005 22:50:37 -0000	1.52
@@ -188,12 +188,18 @@
     "Compile a template pattern, returning a pattern object"
     return _compile(pattern, flags|T)
 
+_alphanum = {}
+for c in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890':
+    _alphanum[c] = 1
+del c
+
 def escape(pattern):
     "Escape all non-alphanumeric characters in pattern."
     s = list(pattern)
+    alphanum = _alphanum
     for i in range(len(pattern)):
         c = pattern[i]
-        if not ("a" <= c <= "z" or "A" <= c <= "Z" or "0" <= c <= "9"):
+        if c not in alphanum:
             if c == "\000":
                 s[i] = "\\000"
             else:



More information about the Python-checkins mailing list