summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-07-20 15:46:13 (GMT)
committerGuido van Rossum <guido@python.org>1998-07-20 15:46:13 (GMT)
commit3a8d1f5a6b6319238aa3afba7751dfc0d36a8fc2 (patch)
tree836cf8118e84c2d09d80b670eb7ed423705e40bf /Lib
parent7333c4cafcbb0c0ea5ad7bed9f5f77c16a844e34 (diff)
downloadcpython-3a8d1f5a6b6319238aa3afba7751dfc0d36a8fc2.zip
cpython-3a8d1f5a6b6319238aa3afba7751dfc0d36a8fc2.tar.gz
cpython-3a8d1f5a6b6319238aa3afba7751dfc0d36a8fc2.tar.bz2
Modest speed improvement to escape() by Piet van Oostrum.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/re.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/Lib/re.py b/Lib/re.py
index 7d5a044..dce29ce 100644
--- 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):