changeset 9387:20ed9909dbd9

templatefilters: indent: do not compute text.endswith('\n') in each iteration
author Nicolas Dumazet <nicdumz.commits@gmail.com>
date Sat, 22 Aug 2009 19:40:15 +0200
parents eae98607b349
children 7cca980317c5 dd8d10c36c9c
files mercurial/templatefilters.py
diffstat 1 files changed, 2 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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())