[Python-checkins] cpython: issue23591: optimize _high_bit()
ethan.furman
python-checkins at python.org
Fri Sep 2 18:50:36 EDT 2016
https://hg.python.org/cpython/rev/31586a2f01b6
changeset: 103010:31586a2f01b6
user: Ethan Furman <ethan at stoneleaf.us>
date: Fri Sep 02 15:50:21 2016 -0700
summary:
issue23591: optimize _high_bit()
files:
Lib/enum.py | 9 ++-------
1 files changed, 2 insertions(+), 7 deletions(-)
diff --git a/Lib/enum.py b/Lib/enum.py
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -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."""
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list