diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-06-23 14:44:48 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-06-23 14:44:48 (GMT) |
commit | 78157b3f6fa220177ef595e30f788dfe9b97d850 (patch) | |
tree | ba6b50c42b7ba0aba1001cd0ac91d3c0ef3e59ce /Lib/zipfile.py | |
parent | 3861d8b27127a261391ee49ff8634a4ef3ba1dd3 (diff) | |
download | cpython-78157b3f6fa220177ef595e30f788dfe9b97d850.zip cpython-78157b3f6fa220177ef595e30f788dfe9b97d850.tar.gz cpython-78157b3f6fa220177ef595e30f788dfe9b97d850.tar.bz2 |
On behalf of Nadeem Vawda: issue #10376: micro-optimize reading from a Zipfile.
(patch by Serhiy)
Diffstat (limited to 'Lib/zipfile.py')
-rw-r--r-- | Lib/zipfile.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py index a6c07e6..209dc4a 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -733,12 +733,13 @@ class ZipExtFile(io.BufferedIOBase): buf += self._read1(self.MAX_N) return buf - n -= len(self._readbuffer) - self._offset - if n < 0: - buf = self._readbuffer[self._offset:n] - self._offset += len(buf) + end = n + self._offset + if end < len(self._readbuffer): + buf = self._readbuffer[self._offset:end] + self._offset = end return buf + n = end - len(self._readbuffer) buf = self._readbuffer[self._offset:] self._readbuffer = b'' self._offset = 0 @@ -774,12 +775,13 @@ class ZipExtFile(io.BufferedIOBase): buf += data return buf - n -= len(self._readbuffer) - self._offset - if n < 0: - buf = self._readbuffer[self._offset:n] - self._offset += len(buf) + end = n + self._offset + if end < len(self._readbuffer): + buf = self._readbuffer[self._offset:end] + self._offset = end return buf + n = end - len(self._readbuffer) buf = self._readbuffer[self._offset:] self._readbuffer = b'' self._offset = 0 |