templatefilters: indent: do not compute text.endswith('\n') in each iteration
authorNicolas Dumazet <nicdumz.commits@gmail.com>
Sat, 22 Aug 2009 19:40:15 +0200
changeset 9387 20ed9909dbd9
parent 9386 eae98607b349
child 9389 7cca980317c5
child 9486 dd8d10c36c9c
templatefilters: indent: do not compute text.endswith('\n') in each iteration
mercurial/templatefilters.py
--- a/mercurial/templatefilters.py	Sat Aug 22 15:47:03 2009 +0200
+++ b/mercurial/templatefilters.py	Sat Aug 22 19:40:15 2009 +0200
@@ -105,13 +105,14 @@
     '''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())