# HG changeset patch # User Nicolas Dumazet # Date 2009-08-22 17:40:15 # Node ID 20ed9909dbd9251f76cacb463c480488eebf736b # Parent eae98607b3499385dd76e738a7379a409960be19 templatefilters: indent: do not compute text.endswith('\n') in each iteration diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py --- a/mercurial/templatefilters.py +++ b/mercurial/templatefilters.py @@ -105,13 +105,14 @@ def indent(text, prefix): '''indent each non-empty line of text after first with prefix.''' lines = text.splitlines() num_lines = len(lines) + endswithnewline = text[-1:] == '\n' def indenter(): for i in xrange(num_lines): l = lines[i] if i and l.strip(): yield prefix yield l - if i < num_lines - 1 or text.endswith('\n'): + if i < num_lines - 1 or endswithnewline: yield '\n' return "".join(indenter())