perf: Count state of properties before set speed
Once the number of properties at a given state are at/above the given
number allowed, set the fan speed and stop checking the remaining
properties.
Tested:
Action function results are unchanged
Change-Id: Icfd347703c973b12f4b7806ea1ba84056f987253
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/actions.hpp b/control/actions.hpp
index c7356ab..b079bf4 100644
--- a/control/actions.hpp
+++ b/control/actions.hpp
@@ -88,27 +88,28 @@
speed,
state = std::forward<T>(state)](auto& zone, auto& group)
{
- size_t numAtState = std::count_if(
- group.begin(),
- group.end(),
- [&zone, &state](auto const& entry)
- {
- try
- {
- return zone.template getPropertyValue<T>(
- entry.first,
- std::get<intfPos>(entry.second),
- std::get<propPos>(entry.second)) == state;
- }
- catch (const std::out_of_range& oore)
- {
- // Default to property not equal when not found
- return false;
- }
- });
- if (numAtState >= count)
+ size_t numAtState = 0;
+ for (auto& entry : group)
{
- zone.setSpeed(speed);
+ try
+ {
+ if (zone.template getPropertyValue<T>(
+ entry.first,
+ std::get<intfPos>(entry.second),
+ std::get<propPos>(entry.second)) == state)
+ {
+ numAtState++;
+ }
+ }
+ catch (const std::out_of_range& oore)
+ {
+ // Default to property not equal when not found
+ }
+ if (numAtState >= count)
+ {
+ zone.setSpeed(speed);
+ break;
+ }
}
// Update group's fan control active allowed based on action results
zone.setActiveAllow(&group, !(numAtState >= count));