changeset 26479:46143f31290e

util.chunkbuffer: refactor chunk handling logic This will make the next patch easier to read. It provides no benefit on its own.
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 05 Oct 2015 16:34:47 -0700
parents a3f7e5461dbd
children 6ae14d1ca3aa
files mercurial/util.py
diffstat 1 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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)