util.chunkbuffer: refactor chunk handling logic
authorGregory Szorc <gregory.szorc@gmail.com>
Mon, 05 Oct 2015 16:34:47 -0700
changeset 26479 46143f31290e
parent 26478 a3f7e5461dbd
child 26480 6ae14d1ca3aa
util.chunkbuffer: refactor chunk handling logic This will make the next patch easier to read. It provides no benefit on its own.
mercurial/util.py
--- a/mercurial/util.py	Mon Oct 05 16:28:12 2015 -0700
+++ b/mercurial/util.py	Mon Oct 05 16:34:47 2015 -0700
@@ -1310,13 +1310,20 @@
                 if not queue:
                     break
 
-            chunk = queue.popleft()
-            left -= len(chunk)
-            if left < 0:
+            chunk = queue[0]
+            chunkl = len(chunk)
+
+            # Use full chunk.
+            if left >= chunkl:
+                left -= chunkl
+                queue.popleft()
+                buf.append(chunk)
+            # Partial chunk needed.
+            else:
+                left -= chunkl
+                queue.popleft()
                 queue.appendleft(chunk[left:])
                 buf.append(chunk[:left])
-            else:
-                buf.append(chunk)
 
         return ''.join(buf)