Fix the spin loop not to be O(n**2).
authorEric S. Raymond <esr@thyrsus.com>
Sun, 20 Oct 2013 21:50:28 +0000 (17:50 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Sun, 20 Oct 2013 21:50:28 +0000 (17:50 -0400)
irkerd

diff --git a/irkerd b/irkerd
index 33e480d56ae04a156f781faad0ebd12426f19202..fd97424ff0a68b6f20f6cc933eba2d6832fcf4c3 100755 (executable)
--- a/irkerd
+++ b/irkerd
@@ -46,7 +46,7 @@ CONNECTION_MAX = 200          # To avoid hitting a thread limit
 version = "1.20"
 
 import sys, getopt, urlparse, time, random, socket, signal, re
-import threading, Queue, SocketServer, select, itertools
+import threading, Queue, SocketServer, select
 import logging
 try:
     import simplejson as json  # Faster, also makes us Python-2.4-compatible
@@ -132,10 +132,10 @@ class IRCClient():
                              if x is not None and x.socket is not None]
                 sockets = [x.socket for x in connected]
                 if sockets:
+                    connmap = dict([(c.socket.fileno(), c) for c in connected])
                     (insocks, _o, _e) = select.select(sockets, [], [], timeout)
-                    for s, c in itertools.product(insocks, self.server_connections):
-                        if s == c.socket:
-                            c.consume()
+                    for s in insocks:
+                        connmap[s.fileno()].consume()
 
                 else:
                     time.sleep(timeout)