Speedup for counting newlines

This commit is contained in:
Toshio Kuratomi 2015-09-02 10:57:40 -07:00
parent 843138e7d9
commit 41da8de094

View file

@ -97,13 +97,15 @@ def _count_newlines_from_end(in_str):
may be thrown away during the templating. may be thrown away during the templating.
''' '''
try:
i = len(in_str) i = len(in_str)
while i > 0: j = i -1
if in_str[i-1] != '\n': while in_str[j] == '\n':
break j -= 1
i -= 1 return i - 1 - j
except IndexError:
return len(in_str) - i # Uncommon cases: zero length string and string containing only newlines
return i
class Templar: class Templar:
''' '''