]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
optimize str bytes concatenation 53/head
authorYun Xu <yunx@zillowgroup.com>
Sat, 11 May 2019 17:08:20 +0000 (10:08 -0700)
committerYun Xu <yunx@zillowgroup.com>
Sat, 11 May 2019 17:08:20 +0000 (10:08 -0700)
httpcore/models.py

index 251f62652aecd061ac3b2975aac2ca66fe31338c..7b6b1aa85fd853df83a199b8b6971f539b6316fd 100644 (file)
@@ -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]: