Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
34ae04f7
Commit
34ae04f7
authored
Dec 26, 2018
by
Andrew Svetlov
Committed by
Ethan Furman
Dec 26, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Speed-up building enums by value, e.g. http.HTTPStatus(200) (#11318)
bpo-35585: Speed up enum by-value lookup
parent
3a81076b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
2 deletions
+5
-2
Lib/enum.py
Lib/enum.py
+4
-2
Misc/NEWS.d/next/Library/2018-12-26-02-28-00.bpo-35585.Lkzd3Z.rst
...S.d/next/Library/2018-12-26-02-28-00.bpo-35585.Lkzd3Z.rst
+1
-0
No files found.
Lib/enum.py
View file @
34ae04f7
...
...
@@ -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
():
...
...
Misc/NEWS.d/next/Library/2018-12-26-02-28-00.bpo-35585.Lkzd3Z.rst
0 → 100644
View file @
34ae04f7
Speed-up building enums by value, e.g. http.HTTPStatus(200).
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment