mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Speedup for counting newlines
This commit is contained in:
parent
843138e7d9
commit
41da8de094
1 changed files with 9 additions and 7 deletions
|
@ -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:
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Reference in a new issue