changeset 11670:1b3b843e1100

chunkbuffer: split big strings directly in chunkbuffer
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Sun, 25 Jul 2010 13:10:57 +0200
parents c47cb3193c53
children ca6ede0988d5
files mercurial/revlog.py mercurial/util.py
diffstat 2 files changed, 12 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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):