mirror of
https://github.com/python/cpython.git
synced 2024-11-27 03:45:08 +08:00
gh-106554: replace _BaseSelectorImpl._key_from_fd
with dict.get
(#106555)
This commit is contained in:
parent
6a70edf24c
commit
aeef8591e4
@ -276,19 +276,6 @@ class _BaseSelectorImpl(BaseSelector):
|
||||
def get_map(self):
|
||||
return self._map
|
||||
|
||||
def _key_from_fd(self, fd):
|
||||
"""Return the key associated to a given file descriptor.
|
||||
|
||||
Parameters:
|
||||
fd -- file descriptor
|
||||
|
||||
Returns:
|
||||
corresponding key, or None if not found
|
||||
"""
|
||||
try:
|
||||
return self._fd_to_key[fd]
|
||||
except KeyError:
|
||||
return None
|
||||
|
||||
|
||||
class SelectSelector(_BaseSelectorImpl):
|
||||
@ -336,7 +323,7 @@ class SelectSelector(_BaseSelectorImpl):
|
||||
if fd in w:
|
||||
events |= EVENT_WRITE
|
||||
|
||||
key = self._key_from_fd(fd)
|
||||
key = self._fd_to_key.get(fd)
|
||||
if key:
|
||||
ready.append((key, events & key.events))
|
||||
return ready
|
||||
@ -426,7 +413,7 @@ class _PollLikeSelector(_BaseSelectorImpl):
|
||||
if event & ~self._EVENT_WRITE:
|
||||
events |= EVENT_READ
|
||||
|
||||
key = self._key_from_fd(fd)
|
||||
key = self._fd_to_key.get(fd)
|
||||
if key:
|
||||
ready.append((key, events & key.events))
|
||||
return ready
|
||||
@ -479,7 +466,7 @@ if hasattr(select, 'epoll'):
|
||||
if event & ~select.EPOLLOUT:
|
||||
events |= EVENT_READ
|
||||
|
||||
key = self._key_from_fd(fd)
|
||||
key = self._fd_to_key.get(fd)
|
||||
if key:
|
||||
ready.append((key, events & key.events))
|
||||
return ready
|
||||
@ -574,7 +561,7 @@ if hasattr(select, 'kqueue'):
|
||||
if flag == select.KQ_FILTER_WRITE:
|
||||
events |= EVENT_WRITE
|
||||
|
||||
key = self._key_from_fd(fd)
|
||||
key = self._fd_to_key.get(fd)
|
||||
if key:
|
||||
ready.append((key, events & key.events))
|
||||
return ready
|
||||
|
@ -0,0 +1 @@
|
||||
:mod:`selectors`: Reduce Selector overhead by using a ``dict.get()`` to lookup file descriptors.
|
Loading…
Reference in New Issue
Block a user