820
820
return pathjoin(*p)
823
def chunks_to_lines(chunks):
824
"""Ensure that chunks is split cleanly into lines.
826
Each entry in the result should contain a single newline at the end. Except
827
for the last entry which may not have a final newline.
829
:param chunks: An iterable of strings
830
:return: A list of strings.
832
# Optimize for a very common case when chunks are already lines
836
# This is a bit ugly, but is the fastest way to check if all of the
837
# chunks are individual lines.
838
# You can't use function calls like .count(), .index(), or endswith()
839
# because they incur too much python overhead.
841
# if chunk is an empty string, it will raise IndexError, which will
843
# if chunk doesn't end with '\n' then we hit fail()
844
# if there is more than one '\n' then we hit fail()
845
# timing shows this loop to take 2.58ms rather than 3.18ms for
846
# split_lines(''.join(chunks))
847
# Further, it means we get to preserve the original lines, rather than
849
[(chunk[-1] == '\n' and '\n' not in chunk[:-1]) or fail()
854
return split_lines(''.join(chunks))
858
824
from bzrlib._chunks_to_lines_pyx import chunks_to_lines
859
825
except ImportError:
826
from bzrlib._chunks_to_lines_py import chunks_to_lines
863
829
def split_lines(s):