Patchwork [4,of,8,V5] worker: change "pids" to a set

login
register
mail settings
Submitter Jun Wu
Date Nov. 15, 2016, 2:39 a.m.
Message ID <2ab9239f357f1739b2a2.1479177547@x1c>
Download mbox | patch
Permalink /patch/17578/
State Accepted
Headers show

Comments

Jun Wu - Nov. 15, 2016, 2:39 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1479175840 0
#      Tue Nov 15 02:10:40 2016 +0000
# Node ID 2ab9239f357f1739b2a230bee69ad5eaa81493a6
# Parent  0abdc39524ef9845a82082f53499d83468ce7761
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 2ab9239f357f
worker: change "pids" to a set

There is no need to keep any order of the "pids" array. A set is more
efficient for the "remove" operation. And the following patch will use that.

Patch

diff --git a/mercurial/worker.py b/mercurial/worker.py
--- a/mercurial/worker.py
+++ b/mercurial/worker.py
@@ -89,5 +89,5 @@  def _posixworker(ui, func, staticargs, a
     oldhandler = signal.getsignal(signal.SIGINT)
     signal.signal(signal.SIGINT, signal.SIG_IGN)
-    pids, problem = [], [0]
+    pids, problem = set(), [0]
     def killworkers():
         # if one worker bails, there's no good reason to wait for the rest
@@ -119,6 +119,5 @@  def _posixworker(ui, func, staticargs, a
                 # other exceptions are allowed to propagate, we rely
                 # on lock.py's pid checks to avoid release callbacks
-        pids.append(pid)
-    pids.reverse()
+        pids.add(pid)
     os.close(wfd)
     fp = os.fdopen(rfd, 'rb', 0)