Skip to content

Commit 549d11d

Browse files
authored
[libc++] Optimize std::has_single_bit
1 parent 96925fa commit 549d11d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

libcxx/include/__bit/has_single_bit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2525

2626
template <__libcpp_unsigned_integer _Tp>
2727
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool has_single_bit(_Tp __t) noexcept {
28-
return __t != 0 && (((__t & (__t - 1)) == 0));
28+
return (__t ^ (__t - 1)) > __t - 1;
2929
}
3030

3131
_LIBCPP_END_NAMESPACE_STD

0 commit comments

Comments
 (0)