comparison mercurial/util.py @ 16873:37e081609828

util: simplify queue management in chunkbuffer This also fixes a small wire protocol performance regression.
author Bryan O'Sullivan <bryano@fb.com>
date Tue, 05 Jun 2012 16:52:20 -0700
parents cafd8a8fb713
children 8d08a28aa63e
comparison
equal deleted inserted replaced
16872:40d930848fd0 16873:37e081609828
868 yield chunk[pos:end] 868 yield chunk[pos:end]
869 pos = end 869 pos = end
870 else: 870 else:
871 yield chunk 871 yield chunk
872 self.iter = splitbig(in_iter) 872 self.iter = splitbig(in_iter)
873 self._queue = [] 873 self._queue = deque()
874 874
875 def read(self, l): 875 def read(self, l):
876 """Read L bytes of data from the iterator of chunks of data. 876 """Read L bytes of data from the iterator of chunks of data.
877 Returns less than L bytes if the iterator runs dry.""" 877 Returns less than L bytes if the iterator runs dry."""
878 left = l 878 left = l
879 buf = '' 879 buf = ''
880 queue = deque(self._queue) 880 queue = self._queue
881 while left > 0: 881 while left > 0:
882 # refill the queue 882 # refill the queue
883 if not queue: 883 if not queue:
884 target = 2**18 884 target = 2**18
885 for chunk in self.iter: 885 for chunk in self.iter:
895 if left < 0: 895 if left < 0:
896 queue.appendleft(chunk[left:]) 896 queue.appendleft(chunk[left:])
897 buf += chunk[:left] 897 buf += chunk[:left]
898 else: 898 else:
899 buf += chunk 899 buf += chunk
900 self._queue = list(queue)
901 900
902 return buf 901 return buf
903 902
904 def filechunkiter(f, size=65536, limit=None): 903 def filechunkiter(f, size=65536, limit=None):
905 """Create a generator that produces the data in the file size 904 """Create a generator that produces the data in the file size