mirror of
https://github.com/boostorg/dynamic_bitset.git
synced 2026-01-19 04:12:09 +00:00
Make lowest_bit() more efficient
As a nice bonus, this also removes the dependency on Boost.Integer.
This commit is contained in:
@@ -46,7 +46,7 @@ if (BOOST_DYNAMIC_BITSET_IS_ROOT)
|
||||
|
||||
# If BOOST_SRC_DIR is valid, fallback to find_package
|
||||
set(CMAKE_FOLDER Dependencies)
|
||||
set(BOOST_INCLUDE_LIBRARIES assert config container_hash core integer move throw_exception)
|
||||
set(BOOST_INCLUDE_LIBRARIES assert config container_hash core move throw_exception)
|
||||
set(BOOST_EXCLUDE_LIBRARIES dynamic_bitset)
|
||||
set(PREV_BUILD_TESTING ${BUILD_TESTING})
|
||||
set(BUILD_TESTING OFF CACHE BOOL "Build the tests." FORCE)
|
||||
@@ -62,7 +62,6 @@ target_link_libraries(boost_dynamic_bitset
|
||||
Boost::config
|
||||
Boost::container_hash
|
||||
Boost::core
|
||||
Boost::integer
|
||||
Boost::move
|
||||
Boost::throw_exception
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ constant boost_dependencies :
|
||||
/boost/config//boost_config
|
||||
/boost/container_hash//boost_container_hash
|
||||
/boost/core//boost_core
|
||||
/boost/integer//boost_integer
|
||||
/boost/move//boost_move
|
||||
/boost/throw_exception//boost_throw_exception ;
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
#define BOOST_LOWEST_BIT_HPP_GP_20030301
|
||||
|
||||
#include "boost/assert.hpp"
|
||||
#include "boost/integer/integer_log2.hpp"
|
||||
#include "boost/core/bit.hpp"
|
||||
#include <type_traits>
|
||||
|
||||
namespace boost {
|
||||
namespace detail {
|
||||
@@ -26,10 +27,7 @@ lowest_bit( T x )
|
||||
{
|
||||
BOOST_ASSERT( x >= 1 );
|
||||
|
||||
// Clear all the bits that are set except the rightmost one,
|
||||
// then calculate the logarithm to base 2.
|
||||
//
|
||||
return boost::integer_log2< T >( x - ( x & ( x - 1 ) ) );
|
||||
return boost::core::countr_zero( static_cast< typename std::make_unsigned< T >::type >( x ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user