[PATCH 4 of 4] templatefilters: indent: do not compute text.endswith('\n') in each iteration

Nicolas Dumazet nicdumz at gmail.com
Sat Aug 22 13:39:45 CDT 2009


# HG changeset patch
# User Nicolas Dumazet <nicdumz.commits at gmail.com>
# Date 1250962815 -7200
# Node ID 0c1c69cb029da197816c6f9c8868a9c9040a86e5
# Parent  a9449df9eef46f7f534fb4dd1eb573721962fa75
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,15 @@
     '''indent each non-empty line of text after first with prefix.'''
     lines = text.splitlines()
     num_lines = len(lines)
+    if num_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())
 


More information about the Mercurial-devel mailing list