diff options
author | Guido van Rossum <guido@python.org> | 1998-07-20 15:46:13 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-07-20 15:46:13 (GMT) |
commit | 3a8d1f5a6b6319238aa3afba7751dfc0d36a8fc2 (patch) | |
tree | 836cf8118e84c2d09d80b670eb7ed423705e40bf /Lib | |
parent | 7333c4cafcbb0c0ea5ad7bed9f5f77c16a844e34 (diff) | |
download | cpython-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.py | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -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): |