-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc++] Use _BitInt and __builtin_popcountg in bitset::count() #160679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -867,7 +867,16 @@ bitset<_Size>::to_string(char __zero, char __one) const { | |
|
||
template <size_t _Size> | ||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 size_t bitset<_Size>::count() const _NOEXCEPT { | ||
return static_cast<size_t>(std::count(__base::__make_iter(0), __base::__make_iter(_Size), true)); | ||
# if defined(_LIBCPP_COMPILER_CLANG_BASED) && !defined(_LIBCPP_CXX03_LANG) | ||
if constexpr (_Size == 0) { | ||
return 0; | ||
} else if constexpr (_Size <= __base::__bits_per_word) { | ||
return __builtin_popcountg(static_cast<unsigned _BitInt(_Size)>(__base::__first_)); | ||
} else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need this #if defined(CLANG)
if constexpr (...) {
// A
} else if constexpr (...) {
// B
}
#endif
return std::count(...); Seems a bit simpler and equivalent. Are you worried about the mere presence of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need the |
||
# endif | ||
{ | ||
return static_cast<size_t>(std::count(__base::__make_iter(0), __base::__make_iter(_Size), true)); | ||
philnik777 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
template <size_t _Size> | ||
|
Uh oh!
There was an error while loading. Please reload this page.