match: optimize escaping in _globre
authorMatt Mackall <mpm@selenic.com>
Sun, 24 May 2009 02:56:14 -0500
changeset 8583 19d1b2aec562
parent 8582 a4c199e12b5a
child 8584 0f06e72abfdc
match: optimize escaping in _globre - localize re.escape - fastpath escaping of non-special characters
mercurial/match.py
--- a/mercurial/match.py	Sun May 24 02:56:14 2009 -0500
+++ b/mercurial/match.py	Sun May 24 02:56:14 2009 -0500
@@ -125,11 +125,14 @@
     i, n = 0, len(pat)
     res = ''
     group = 0
+    escape = re.escape
     def peek(): return i < n and pat[i]
     while i < n:
         c = pat[i]
         i = i+1
-        if c == '*':
+        if c not in '*?[{},\\':
+            res += escape(c)
+        elif c == '*':
             if peek() == '*':
                 i += 1
                 res += '.*'
@@ -165,11 +168,11 @@
             p = peek()
             if p:
                 i += 1
-                res += re.escape(p)
+                res += escape(p)
             else:
-                res += re.escape(c)
+                res += escape(c)
         else:
-            res += re.escape(c)
+            res += escape(c)
     return res
 
 def _regex(kind, name, tail):