]> granicus.if.org Git - python/commitdiff
Modest speed improvement to escape() by Piet van Oostrum.
authorGuido van Rossum <guido@python.org>
Mon, 20 Jul 1998 15:46:13 +0000 (15:46 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 20 Jul 1998 15:46:13 +0000 (15:46 +0000)
Lib/re.py

index 7d5a0449d2c627f6959fe728282f7137017ba72f..dce29ceac9921dd2592658b3220d7b1135e6b069 100644 (file)
--- a/Lib/re.py
+++ b/Lib/re.py
@@ -64,13 +64,13 @@ def findall(pattern, string):
 
 def escape(pattern):
     "Escape all non-alphanumeric characters in pattern."
-    result = []
+    result = list(pattern)
     alphanum=string.letters+'_'+string.digits
-    for char in pattern:
+    for i in range(len(pattern)):
+        char = pattern[i]
         if char not in alphanum:
-            if char=='\000': result.append('\\000')
-            else: result.append('\\'+char)
-        else: result.append(char)
+            if char=='\000': result[i] = '\\000'
+            else: result[i] = '\\'+char
     return string.join(result, '')
 
 def compile(pattern, flags=0):