summaryrefslogtreecommitdiffstats
path: root/Lib/selectors.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@dropbox.com>2013-11-07 16:39:28 (GMT)
committerGuido van Rossum <guido@dropbox.com>2013-11-07 16:39:28 (GMT)
commitd0786a1a5036c06770f1c958323387fd682e789e (patch)
tree69a5d2bc9cdea0202c72144e852ad9ec2f4bc590 /Lib/selectors.py
parentb7038817fee37fea81183d64c9dd957bab571fde (diff)
downloadcpython-d0786a1a5036c06770f1c958323387fd682e789e.zip
cpython-d0786a1a5036c06770f1c958323387fd682e789e.tar.gz
cpython-d0786a1a5036c06770f1c958323387fd682e789e.tar.bz2
Optimize BaseSelector.modify(). Patch by Arnaud Faure.
Diffstat (limited to 'Lib/selectors.py')
-rw-r--r--Lib/selectors.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/Lib/selectors.py b/Lib/selectors.py
index 3638e85..3971502 100644
--- a/Lib/selectors.py
+++ b/Lib/selectors.py
@@ -138,11 +138,14 @@ class BaseSelector(metaclass=ABCMeta):
key = self._fd_to_key[_fileobj_to_fd(fileobj)]
except KeyError:
raise KeyError("{!r} is not registered".format(fileobj)) from None
- if events != key.events or data != key.data:
- # TODO: If only the data changed, use a shortcut that only
- # updates the data.
+ if events != key.events:
self.unregister(fileobj)
return self.register(fileobj, events, data)
+ elif data != key.data:
+ # Use a shortcut to update the data.
+ key = key._replace(data=data)
+ self._fd_to_key[key.fd] = key
+ return key
else:
return key