From: Yun Xu Date: Sat, 11 May 2019 17:08:20 +0000 (-0700) Subject: optimize str bytes concatenation X-Git-Tag: 0.3.0~26^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b1c4d8acf6a31e807cc1f31c178e124e2a1779ca;p=thirdparty%2Fhttpx.git optimize str bytes concatenation --- 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]: