Mercurial > hg
changeset 5447:56591846f819
chunkiter: simplify iter logic
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 11 Oct 2007 00:46:49 -0500 |
parents | fa836e050c50 |
children | e038738714fd |
files | mercurial/util.py |
diffstat | 1 files changed, 4 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/util.py Thu Oct 11 00:46:48 2007 -0500 +++ b/mercurial/util.py Thu Oct 11 00:46:49 2007 -0500 @@ -1399,27 +1399,26 @@ def __init__(self, in_iter): """in_iter is the iterator that's iterating over the input chunks. targetsize is how big a buffer to try to maintain.""" - self.in_iter = iter(in_iter) + self.iter = iter(in_iter) self.buf = '' self.targetsize = 2**16 - self.iterempty = False def read(self, l): """Read L bytes of data from the iterator of chunks of data. Returns less than L bytes if the iterator runs dry.""" - if l > len(self.buf) and not self.iterempty: + if l > len(self.buf) and self.iter: # Clamp to a multiple of self.targetsize targetsize = self.targetsize * ((l // self.targetsize) + 1) collector = cStringIO.StringIO() collector.write(self.buf) collected = len(self.buf) - for chunk in self.in_iter: + for chunk in self.iter: collector.write(chunk) collected += len(chunk) if collected >= targetsize: break if collected < targetsize: - self.iterempty = True + self.iter = False self.buf = collector.getvalue() s, self.buf = self.buf[:l], buffer(self.buf, l) return s