Commit 41da8de0 by Toshio Kuratomi

Speedup for counting newlines

parent 843138e7
...@@ -97,13 +97,15 @@ def _count_newlines_from_end(in_str): ...@@ -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.
''' '''
i = len(in_str) try:
while i > 0: i = len(in_str)
if in_str[i-1] != '\n': j = i -1
break while in_str[j] == '\n':
i -= 1 j -= 1
return i - 1 - j
return len(in_str) - i except IndexError:
# Uncommon cases: zero length string and string containing only newlines
return i
class Templar: class Templar:
''' '''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment