For effiency, set newline character outside of loop

This commit is contained in:
Andrew Murray 2020-02-15 20:53:02 +11:00
parent f958e2f8ed
commit 8acf77a042

View File

@ -93,12 +93,13 @@ class ContainerIO:
:returns: An 8-bit string.
"""
s = b"" if "b" in self.fh.mode else ""
newline_character = b"\n" if "b" in self.fh.mode else "\n"
while True:
c = self.read(1)
if not c:
break
s = s + c
if c == (b"\n" if "b" in self.fh.mode else "\n"):
if c == newline_character:
break
return s