From c731a077fb44144f0c6e40281e4ffce0cd7e3e1e Mon Sep 17 00:00:00 2001 From: Robey Pointer Date: Tue, 25 Jul 2006 17:29:47 -0700 Subject: [PATCH] [project @ robey@lag.net-20060726002947-e60cb0a3d7b86919] don't fetch readv chunks that we have reason to believe are already in prefetch buffers. no longer need to order the prefetch requests either. --- paramiko/sftp_file.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/paramiko/sftp_file.py b/paramiko/sftp_file.py index 3673e86..5294899 100644 --- a/paramiko/sftp_file.py +++ b/paramiko/sftp_file.py @@ -388,23 +388,20 @@ class SFTPFile (BufferedFile): @since: 1.5.4 """ - # put the offsets in order, since we depend on that for determining - # when the reads have finished. self.sftp._log(DEBUG, 'readv(%s, %r)' % (util.hexify(self.handle), chunks)) - ordered_chunks = list(chunks) - ordered_chunks.sort(lambda x, y: cmp(x[0], y[0])) - # break up anything larger than the max read size - if len([size for offset, size in ordered_chunks if size > self.MAX_REQUEST_SIZE]) > 0: - read_chunks = [] - for offset, size in ordered_chunks: - while size > 0: - chunk_size = min(size, self.MAX_REQUEST_SIZE) - read_chunks.append((offset, chunk_size)) - offset += chunk_size - size -= chunk_size - else: - read_chunks = ordered_chunks + read_chunks = [] + for offset, size in chunks: + # don't fetch data that's already in the prefetch buffer + if self._data_in_prefetch_buffers(offset): + continue + + # break up anything larger than the max read size + while size > 0: + chunk_size = min(size, self.MAX_REQUEST_SIZE) + read_chunks.append((offset, chunk_size)) + offset += chunk_size + size -= chunk_size self._start_prefetch(read_chunks) # now we can just devolve to a bunch of read()s :)