chunkbuffer: split big strings directly in chunkbuffer
authorBenoit Boissinot <benoit.boissinot@ens-lyon.org>
Sun, 25 Jul 2010 13:10:57 +0200
changeset 11670 1b3b843e1100
parent 11669 c47cb3193c53
child 11671 ca6ede0988d5
chunkbuffer: split big strings directly in chunkbuffer
mercurial/revlog.py
mercurial/util.py
--- a/mercurial/revlog.py	Sun Jul 25 10:05:38 2010 +0900
+++ b/mercurial/revlog.py	Sun Jul 25 13:10:57 2010 +0200
@@ -1193,14 +1193,7 @@
                 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()
 
--- a/mercurial/util.py	Sun Jul 25 10:05:38 2010 +0900
+++ b/mercurial/util.py	Sun Jul 25 13:10:57 2010 +0200
@@ -914,7 +914,17 @@
     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):