aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/selectors.py
diff options
context:
space:
mode:
authorDong-hee Na <donghee.na@python.org>2023-07-19 15:12:38 +0900
committerGitHub <noreply@github.com>2023-07-19 15:12:38 +0900
commite6f96cf9c62e38514e8f5465a1c43f85d861adb2 (patch)
tree9028020d6ac880a9b0c0aac5b4221b8c5c6c23e5 /Lib/selectors.py
parent7513e2e7e48f6c004ed9bce55f2dcc6b388e02cd (diff)
downloadcpython-e6f96cf9c62e38514e8f5465a1c43f85d861adb2.tar.gz
cpython-e6f96cf9c62e38514e8f5465a1c43f85d861adb2.zip
gh-106751: Optimize SelectSelector.select() for many iteration case (gh-106879)
Diffstat (limited to 'Lib/selectors.py')
-rw-r--r--Lib/selectors.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/Lib/selectors.py b/Lib/selectors.py
index d13405963f2..13497a24097 100644
--- a/Lib/selectors.py
+++ b/Lib/selectors.py
@@ -314,17 +314,15 @@ class SelectSelector(_BaseSelectorImpl):
r, w, _ = self._select(self._readers, self._writers, [], timeout)
except InterruptedError:
return ready
- r = set(r)
- w = set(w)
- for fd in r | w:
- events = 0
- if fd in r:
- events |= EVENT_READ
- if fd in w:
- events |= EVENT_WRITE
-
- key = self._fd_to_key.get(fd)
+ r = frozenset(r)
+ w = frozenset(w)
+ rw = r | w
+ fd_to_key_get = self._fd_to_key.get
+ for fd in rw:
+ key = fd_to_key_get(fd)
if key:
+ events = ((fd in r and EVENT_READ)
+ | (fd in w and EVENT_WRITE))
ready.append((key, events & key.events))
return ready