mercurial/worker.py
changeset 28181 f8efc8a3a991
parent 26587 56b2bcea2529
child 28292 3eb7faf6d958
--- a/mercurial/worker.py	Thu Feb 18 08:52:15 2016 +0000
+++ b/mercurial/worker.py	Sat Feb 20 15:56:44 2016 -0800
@@ -152,14 +152,11 @@
     _exitstatus = _posixexitstatus
 
 def partition(lst, nslices):
-    '''partition a list into N slices of equal size'''
-    n = len(lst)
-    chunk, slop = n / nslices, n % nslices
-    end = 0
-    for i in xrange(nslices):
-        start = end
-        end = start + chunk
-        if slop:
-            end += 1
-            slop -= 1
-        yield lst[start:end]
+    '''partition a list into N slices of roughly equal size
+
+    The current strategy takes every Nth element from the input. If
+    we ever write workers that need to preserve grouping in input
+    we should consider allowing callers to specify a partition strategy.
+    '''
+    for i in range(nslices):
+        yield lst[i::nslices]