changeset: 103010:31586a2f01b6 user: Ethan Furman date: Fri Sep 02 15:50:21 2016 -0700 files: Lib/enum.py description: issue23591: optimize _high_bit() diff -r 12ce8e0413f1 -r 31586a2f01b6 Lib/enum.py --- a/Lib/enum.py Fri Sep 02 12:12:23 2016 +0200 +++ b/Lib/enum.py Fri Sep 02 15:50:21 2016 -0700 @@ -784,13 +784,8 @@ 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."""