From b1c4d8acf6a31e807cc1f31c178e124e2a1779ca Mon Sep 17 00:00:00 2001 From: Yun Xu Date: Sat, 11 May 2019 10:08:20 -0700 Subject: [PATCH] optimize str bytes concatenation --- httpcore/models.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/httpcore/models.py b/httpcore/models.py index 251f6265..7b6b1aa8 100644 --- a/httpcore/models.py +++ b/httpcore/models.py @@ -482,10 +482,7 @@ class Request: Read and return the response content. """ if not hasattr(self, "content"): - content = b"" - async for part in self.stream(): - content += part - self.content = content + self.content = b"".join([part async for part in self.stream()]) return self.content async def stream(self) -> typing.AsyncIterator[bytes]: @@ -670,10 +667,7 @@ class Response: Read and return the response content. """ if not hasattr(self, "_content"): - content = b"" - async for part in self.stream(): - content += part - self._content = content + self._content = b"".join([part async for part in self.stream()]) return self._content async def stream(self) -> typing.AsyncIterator[bytes]: -- 2.47.3