# HG changeset patch # User Matt Mackall # Date 2009-05-24 07:56:14 # Node ID 19d1b2aec562830d2a4ac199e6bbb9f65c122352 # Parent a4c199e12b5aaf59d36b14507a86d3c0200d57c8 match: optimize escaping in _globre - localize re.escape - fastpath escaping of non-special characters diff --git a/mercurial/match.py b/mercurial/match.py --- a/mercurial/match.py +++ b/mercurial/match.py @@ -125,11 +125,14 @@ def _globre(pat): 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 @@ def _globre(pat): 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):