summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorDong-hee Na <donghee.na@python.org>2023-07-19 01:18:23 (GMT)
committerGitHub <noreply@github.com>2023-07-19 01:18:23 (GMT)
commit7513e2e7e48f6c004ed9bce55f2dcc6b388e02cd (patch)
tree8d046f35f32aad3a20e40bf26dd80be0a9832944 /Lib
parent663854d73b35feeb004ae0970e45b53ca27774a1 (diff)
downloadcpython-7513e2e7e48f6c004ed9bce55f2dcc6b388e02cd.zip
cpython-7513e2e7e48f6c004ed9bce55f2dcc6b388e02cd.tar.gz
cpython-7513e2e7e48f6c004ed9bce55f2dcc6b388e02cd.tar.bz2
gh-106751: Optimize KqueueSelector.select() for many iteration case (gh-106864)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/selectors.py14
1 files changed, 6 insertions, 8 deletions
diff --git a/Lib/selectors.py b/Lib/selectors.py
index a42d156..d134059 100644
--- a/Lib/selectors.py
+++ b/Lib/selectors.py
@@ -547,23 +547,21 @@ if hasattr(select, 'kqueue'):
# If max_ev is 0, kqueue will ignore the timeout. For consistent
# behavior with the other selector classes, we prevent that here
# (using max). See https://bugs.python.org/issue29255
- max_ev = max(len(self._fd_to_key), 1)
+ max_ev = len(self._fd_to_key) or 1
ready = []
try:
kev_list = self._selector.control(None, max_ev, timeout)
except InterruptedError:
return ready
+
+ fd_to_key_get = self._fd_to_key.get
for kev in kev_list:
fd = kev.ident
flag = kev.filter
- events = 0
- if flag == select.KQ_FILTER_READ:
- events |= EVENT_READ
- if flag == select.KQ_FILTER_WRITE:
- events |= EVENT_WRITE
-
- key = self._fd_to_key.get(fd)
+ key = fd_to_key_get(fd)
if key:
+ events = ((flag == select.KQ_FILTER_READ and EVENT_READ)
+ | (flag == select.KQ_FILTER_WRITE and EVENT_WRITE))
ready.append((key, events & key.events))
return ready