mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	gh-106554: replace _BaseSelectorImpl._key_from_fd with dict.get (#106555)
				
					
				
			This commit is contained in:
		
							parent
							
								
									6a70edf24c
								
							
						
					
					
						commit
						aeef8591e4
					
				
					 2 changed files with 5 additions and 17 deletions
				
			
		|  | @ -276,19 +276,6 @@ def close(self): | ||||||
|     def get_map(self): |     def get_map(self): | ||||||
|         return self._map |         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): | class SelectSelector(_BaseSelectorImpl): | ||||||
|  | @ -336,7 +323,7 @@ def select(self, timeout=None): | ||||||
|             if fd in w: |             if fd in w: | ||||||
|                 events |= EVENT_WRITE |                 events |= EVENT_WRITE | ||||||
| 
 | 
 | ||||||
|             key = self._key_from_fd(fd) |             key = self._fd_to_key.get(fd) | ||||||
|             if key: |             if key: | ||||||
|                 ready.append((key, events & key.events)) |                 ready.append((key, events & key.events)) | ||||||
|         return ready |         return ready | ||||||
|  | @ -426,7 +413,7 @@ def select(self, timeout=None): | ||||||
|             if event & ~self._EVENT_WRITE: |             if event & ~self._EVENT_WRITE: | ||||||
|                 events |= EVENT_READ |                 events |= EVENT_READ | ||||||
| 
 | 
 | ||||||
|             key = self._key_from_fd(fd) |             key = self._fd_to_key.get(fd) | ||||||
|             if key: |             if key: | ||||||
|                 ready.append((key, events & key.events)) |                 ready.append((key, events & key.events)) | ||||||
|         return ready |         return ready | ||||||
|  | @ -479,7 +466,7 @@ def select(self, timeout=None): | ||||||
|                 if event & ~select.EPOLLOUT: |                 if event & ~select.EPOLLOUT: | ||||||
|                     events |= EVENT_READ |                     events |= EVENT_READ | ||||||
| 
 | 
 | ||||||
|                 key = self._key_from_fd(fd) |                 key = self._fd_to_key.get(fd) | ||||||
|                 if key: |                 if key: | ||||||
|                     ready.append((key, events & key.events)) |                     ready.append((key, events & key.events)) | ||||||
|             return ready |             return ready | ||||||
|  | @ -574,7 +561,7 @@ def select(self, timeout=None): | ||||||
|                 if flag == select.KQ_FILTER_WRITE: |                 if flag == select.KQ_FILTER_WRITE: | ||||||
|                     events |= EVENT_WRITE |                     events |= EVENT_WRITE | ||||||
| 
 | 
 | ||||||
|                 key = self._key_from_fd(fd) |                 key = self._fd_to_key.get(fd) | ||||||
|                 if key: |                 if key: | ||||||
|                     ready.append((key, events & key.events)) |                     ready.append((key, events & key.events)) | ||||||
|             return ready |             return ready | ||||||
|  |  | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | :mod:`selectors`: Reduce Selector overhead by using a ``dict.get()`` to lookup file descriptors. | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 J. Nick Koston
						J. Nick Koston