Improve loops & fix cpp check warning
- This commit improves certain while loops to range based for loops.
- This commit also fixes the cppcheck warning that mentions about
performance issues when using postfix operators on non-primitive
types.
Tested By:
- A function is unittested.
- GET on both EthernetInterfaces & certificate service
looks good without any issues.
Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
Change-Id: I85420f7bf9af45a97e1a93b916f292c2516f5802
diff --git a/redfish-core/lib/certificate_service.hpp b/redfish-core/lib/certificate_service.hpp
index 5dc1e1f..81d9d05 100644
--- a/redfish-core/lib/certificate_service.hpp
+++ b/redfish-core/lib/certificate_service.hpp
@@ -516,7 +516,7 @@
std::string_view::iterator tokenBegin = i;
while (i != value.end() && *i != '=')
{
- i++;
+ ++i;
}
if (i == value.end())
{
@@ -524,11 +524,11 @@
}
const std::string_view key(tokenBegin,
static_cast<size_t>(i - tokenBegin));
- i++;
+ ++i;
tokenBegin = i;
while (i != value.end() && *i != ',')
{
- i++;
+ ++i;
}
const std::string_view val(tokenBegin,
static_cast<size_t>(i - tokenBegin));
@@ -559,7 +559,7 @@
// skip comma character
if (i != value.end())
{
- i++;
+ ++i;
}
}
}
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 55f1cf5..48b69a2 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -1375,34 +1375,26 @@
boost::container::flat_set<IPv4AddressData>::const_iterator
getNextStaticIpEntry(
- boost::container::flat_set<IPv4AddressData>::const_iterator head,
+ const boost::container::flat_set<IPv4AddressData>::const_iterator&
+ head,
const boost::container::flat_set<IPv4AddressData>::const_iterator&
end)
{
- for (; head != end; head++)
- {
- if (head->origin == "Static")
- {
- return head;
- }
- }
- return end;
+ return std::find_if(head, end, [](const IPv4AddressData& value) {
+ return value.origin == "Static";
+ });
}
boost::container::flat_set<IPv6AddressData>::const_iterator
getNextStaticIpEntry(
- boost::container::flat_set<IPv6AddressData>::const_iterator head,
+ const boost::container::flat_set<IPv6AddressData>::const_iterator&
+ head,
const boost::container::flat_set<IPv6AddressData>::const_iterator&
end)
{
- for (; head != end; head++)
- {
- if (head->origin == "Static")
- {
- return head;
- }
- }
- return end;
+ return std::find_if(head, end, [](const IPv6AddressData& value) {
+ return value.origin == "Static";
+ });
}
void handleIPv4StaticPatch(
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index 26c2125..c621de3 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -1520,7 +1520,7 @@
std::string& type = containerPair.first;
for (nlohmann::json::iterator it = container->begin();
- it != container->end(); it++)
+ it != container->end(); ++it)
{
const auto& name = it.key();
BMCWEB_LOG_DEBUG << "looking for " << name;