Remove getBitfieldCount method
Remove the getBitfieldCount method and use the C++20 feature
`std::popcount` to get the number of bits of 1.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I71a5c1a9e10f508ce58a01ec8dc17ed5d96ed8a5
diff --git a/libpldmresponder/pdr_utils.hpp b/libpldmresponder/pdr_utils.hpp
index 9406d46..c463f1f 100644
--- a/libpldmresponder/pdr_utils.hpp
+++ b/libpldmresponder/pdr_utils.hpp
@@ -89,26 +89,6 @@
return Json::parse(jsonFile);
}
-/** @brief Function to get the Bitfield count to 1
- *
- * @param[in] bit - Bitfield
- *
- * @return - uint8_t return the number of 1
- */
-inline uint8_t getBitfieldCount(const bitfield8_t bit)
-{
- uint8_t count = 0;
- for (uint8_t i = 0; i < 8; ++i)
- {
- if (bit.byte & (1 << i))
- {
- ++count;
- }
- }
-
- return count;
-}
-
/** @brief Populate the mapping between D-Bus property stateId and attribute
* value for the effecter PDR enumeration attribute.
*
diff --git a/libpldmresponder/platform.cpp b/libpldmresponder/platform.cpp
index 893cc83..779a0cd 100644
--- a/libpldmresponder/platform.cpp
+++ b/libpldmresponder/platform.cpp
@@ -615,7 +615,7 @@
}
// 0x01 to 0x08
- uint8_t sensorRearmCount = getBitfieldCount(sensorRearm);
+ uint8_t sensorRearmCount = std::popcount(sensorRearm.byte);
std::vector<get_sensor_state_field> stateField(sensorRearmCount);
uint8_t comSensorCnt{};
const pldm::utils::DBusHandler dBusIntf;