summaryrefslogtreecommitdiffstats
path: root/Lib/enum.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2016-09-02 22:50:21 (GMT)
committerEthan Furman <ethan@stoneleaf.us>2016-09-02 22:50:21 (GMT)
commit044395306702fc47e63b43d5ad961a127c19b262 (patch)
tree5aeb65acd2c912507580336f402bc4324e7f688e /Lib/enum.py
parent1a05d6c04d2a499a7485b15668f2eb37f9f60e3a (diff)
downloadcpython-044395306702fc47e63b43d5ad961a127c19b262.zip
cpython-044395306702fc47e63b43d5ad961a127c19b262.tar.gz
cpython-044395306702fc47e63b43d5ad961a127c19b262.tar.bz2
issue23591: optimize _high_bit()
Diffstat (limited to 'Lib/enum.py')
-rw-r--r--Lib/enum.py9
1 files changed, 2 insertions, 7 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index 8369631..8d23933 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -784,13 +784,8 @@ class IntFlag(int, Flag):
def _high_bit(value):
- """return the highest bit set in value"""
- bit = 0
- while 'looking for the highest bit':
- limit = 2 ** bit
- if limit > value:
- return bit - 1
- bit += 1
+ """returns index of highest bit, or -1 if value is zero or negative"""
+ return value.bit_length() - 1 if value > 0 else -1
def unique(enumeration):
"""Class decorator for enumerations ensuring unique member values."""