mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	Speed-up building enums by value, e.g. http.HTTPStatus(200) (#11318)
bpo-35585: Speed up enum by-value lookup
This commit is contained in:
		
							parent
							
								
									3a81076bbf
								
							
						
					
					
						commit
						34ae04f74d
					
				
					 2 changed files with 5 additions and 2 deletions
				
			
		|  | @ -563,8 +563,10 @@ def __new__(cls, value): | |||
|         # by-value search for a matching enum member | ||||
|         # see if it's in the reverse mapping (for hashable values) | ||||
|         try: | ||||
|             if value in cls._value2member_map_: | ||||
|                 return cls._value2member_map_[value] | ||||
|             return cls._value2member_map_[value] | ||||
|         except KeyError: | ||||
|             # Not found, no need to do long O(n) search | ||||
|             pass | ||||
|         except TypeError: | ||||
|             # not there, now do long search -- O(n) behavior | ||||
|             for member in cls._member_map_.values(): | ||||
|  |  | |||
|  | @ -0,0 +1 @@ | |||
| Speed-up building enums by value, e.g. http.HTTPStatus(200). | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andrew Svetlov
						Andrew Svetlov