From ebfd1486d884190dd26b7af5c694b9dadccd85c3 Mon Sep 17 00:00:00 2001 From: fa08c <0xfa08c@gmail.com> Date: Mon, 12 Jan 2015 10:32:03 +0800 Subject: [PATCH] Removing the overhead of creating a new list per event --- shadowsocks/eventloop.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/shadowsocks/eventloop.py b/shadowsocks/eventloop.py index 2b2459f..304b229 100644 --- a/shadowsocks/eventloop.py +++ b/shadowsocks/eventloop.py @@ -232,9 +232,10 @@ class EventLoop(object): logging.error(e) import traceback traceback.print_exc() - for handler in self._handlers_to_remove: - self._handlers.remove(handler) - self._handlers_to_remove = [] + if self._handlers_to_remove: + for handler in self._handlers_to_remove: + self._handlers.remove(handler) + self._handlers_to_remove = [] self._iterating = False