Mercurial > cpython-lru_cache-weakref
diff Lib/http/client.py @ 55834:266d7dc3d655 3.1
Fixes issue #6838: use a list to accumulate the value instead of repeatedly concatenating strings.
| author | Chris Withers <chris@simplistix.co.uk> |
|---|---|
| date | Fri, 04 Sep 2009 17:15:46 +0000 |
| parents | 5112a56df977 |
| children | a17cd9fcdd46 |
line wrap: on
line diff
--- a/Lib/http/client.py Thu Sep 03 21:32:00 2009 +0000 +++ b/Lib/http/client.py Fri Sep 04 17:15:46 2009 +0000 @@ -518,10 +518,7 @@ def _read_chunked(self, amt): assert self.chunked != _UNKNOWN chunk_left = self.chunk_left - value = b"" - - # XXX This accumulates chunks by repeated string concatenation, - # which is not efficient as the number or size of chunks gets big. + value = [] while True: if chunk_left is None: line = self.fp.readline() @@ -534,22 +531,22 @@ # close the connection as protocol synchronisation is # probably lost self.close() - raise IncompleteRead(value) + raise IncompleteRead(b''.join(value)) if chunk_left == 0: break if amt is None: - value += self._safe_read(chunk_left) + value.append(self._safe_read(chunk_left)) elif amt < chunk_left: - value += self._safe_read(amt) + value.append(self._safe_read(amt)) self.chunk_left = chunk_left - amt - return value + return b''.join(value) elif amt == chunk_left: - value += self._safe_read(amt) + value.append(self._safe_read(amt)) self._safe_read(2) # toss the CRLF at the end of the chunk self.chunk_left = None - return value + return b''.join(value) else: - value += self._safe_read(chunk_left) + value.append(self._safe_read(chunk_left)) amt -= chunk_left # we read the whole chunk, get another @@ -570,7 +567,7 @@ # we read everything; close the "file" self.close() - return value + return b''.join(value) def _safe_read(self, amt): """Read the number of bytes requested, compensating for partial reads.
