Mercurial > public > mercurial-scm > hg
diff mercurial/pure/bdiff.py @ 15530:eeac5e179243
mdiff: replace wscleanup() regexps with C loops
On my system it reduces:
hg annotate -w mercurial/commands.py
from 36s to less than 8s, to be compared with 6.3s when run without whitespace
options.
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Fri, 18 Nov 2011 14:23:03 +0100 |
parents | 14fac6c0536a |
children | c4e3ff497f89 |
line wrap: on
line diff
--- a/mercurial/pure/bdiff.py Fri Nov 18 14:16:47 2011 +0100 +++ b/mercurial/pure/bdiff.py Fri Nov 18 14:23:03 2011 +0100 @@ -5,7 +5,7 @@ # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. -import struct, difflib +import struct, difflib, re def splitnewlines(text): '''like str.splitlines, but only split on newlines.''' @@ -78,3 +78,10 @@ d = _normalizeblocks(an, bn, d) return [(i, i + n, j, j + n) for (i, j, n) in d] +def fixws(text, allws): + if allws: + text = re.sub('[ \t\r]+', '', text) + else: + text = re.sub('[ \t\r]+', ' ', text) + text = text.replace(' \n', '\n') + return text