diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-07-04 08:32:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-04 08:32:41 (GMT) |
commit | c1b75b5fb92fda0ac5b931d7b18c1418557cb7c4 (patch) | |
tree | 2a063a9c858d9baeb2ac0f97700efac1f50b740a /Lib/tarfile.py | |
parent | 2cbd1bb1f342760ce7c1b78d1ef5697c32f1e299 (diff) | |
download | cpython-c1b75b5fb92fda0ac5b931d7b18c1418557cb7c4.zip cpython-c1b75b5fb92fda0ac5b931d7b18c1418557cb7c4.tar.gz cpython-c1b75b5fb92fda0ac5b931d7b18c1418557cb7c4.tar.bz2 |
bpo-34010: Fix tarfile read performance regression (GH-8020)
During buffered read, use a list followed by join instead of extending a bytes object.
This is how it was done before but changed in commit b506dc32c1a.
(cherry picked from commit 12a08c47601cadea8e7d3808502cdbcca87b2ce2)
Co-authored-by: hajoscher <hajoscher@gmail.com>
Diffstat (limited to 'Lib/tarfile.py')
-rwxr-xr-x | Lib/tarfile.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py index 85119a4..edd31e9 100755 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -532,7 +532,7 @@ class _Stream: if not buf: break t.append(buf) - buf = "".join(t) + buf = b"".join(t) else: buf = self._read(size) self.pos += len(buf) @@ -545,6 +545,7 @@ class _Stream: return self.__read(size) c = len(self.dbuf) + t = [self.dbuf] while c < size: buf = self.__read(self.bufsize) if not buf: @@ -553,26 +554,27 @@ class _Stream: buf = self.cmp.decompress(buf) except self.exception: raise ReadError("invalid compressed data") - self.dbuf += buf + t.append(buf) c += len(buf) - buf = self.dbuf[:size] - self.dbuf = self.dbuf[size:] - return buf + t = b"".join(t) + self.dbuf = t[size:] + return t[:size] def __read(self, size): """Return size bytes from stream. If internal buffer is empty, read another block from the stream. """ c = len(self.buf) + t = [self.buf] while c < size: buf = self.fileobj.read(self.bufsize) if not buf: break - self.buf += buf + t.append(buf) c += len(buf) - buf = self.buf[:size] - self.buf = self.buf[size:] - return buf + t = b"".join(t) + self.buf = t[size:] + return t[:size] # class _Stream class _StreamProxy(object): |