# HG changeset patch # User Benoit Boissinot # Date 2010-07-25 11:10:57 # Node ID 1b3b843e11002e95e8675f8028e478122e076def # Parent c47cb3193c534f6899e32e26bf9510da2ef0b7d5 chunkbuffer: split big strings directly in chunkbuffer diff --git a/mercurial/revlog.py b/mercurial/revlog.py --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -1193,14 +1193,7 @@ class revlog(object): d = self.revdiff(a, b) yield changegroup.chunkheader(len(meta) + len(d)) yield meta - if len(d) > 2**20: - pos = 0 - while pos < len(d): - pos2 = pos + 2 ** 18 - yield d[pos:pos2] - pos = pos2 - else: - yield d + yield d yield changegroup.closechunk() diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -914,7 +914,17 @@ class chunkbuffer(object): 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.iter = iter(in_iter) + def splitbig(chunks): + for chunk in chunks: + if len(chunk) > 2**20: + pos = 0 + while pos < len(chunk): + end = pos + 2 ** 18 + yield chunk[pos:end] + pos = end + else: + yield chunk + self.iter = splitbig(in_iter) self.buf = '' def read(self, l):