From 2cd1dc8f04c309a758fc25ddac8e2ca1d6cca683 Mon Sep 17 00:00:00 2001 From: Samuel Li Date: Tue, 30 Apr 2024 16:00:59 -0600 Subject: [PATCH] use bit operations for count_true --- src/Bitmask.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Bitmask.cpp b/src/Bitmask.cpp index 3278cf38..36df72e5 100644 --- a/src/Bitmask.cpp +++ b/src/Bitmask.cpp @@ -124,10 +124,14 @@ auto sperr::Bitmask::count_true() const -> size_t // Note that unused bits in the last long are not guaranteed to be all 0's. for (size_t i = 0; i < m_buf.size() - 1; i++) { const auto val = m_buf[i]; +#if __cplusplus >= 201907L + counter += std::popcount(val); +#else if (val != 0) { for (size_t j = 0; j < 64; j++) counter += ((val >> j) & uint64_t{1}); } +#endif } const auto val = m_buf.back(); if (val != 0) {