Commit 34ae04f7 authored by Andrew Svetlov's avatar Andrew Svetlov Committed by Ethan Furman

Speed-up building enums by value, e.g. http.HTTPStatus(200) (#11318)

bpo-35585: Speed up enum by-value lookup
parent 3a81076b
......@@ -563,8 +563,10 @@ class Enum(metaclass=EnumMeta):
# 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():
......
Speed-up building enums by value, e.g. http.HTTPStatus(200).
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment