From e0f67c8b81d9b19d277e53c1c1a5c169ef54ed82 Mon Sep 17 00:00:00 2001 From: Matthew Barth Date: Tue, 8 May 2018 15:47:12 -0500 Subject: 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 --- control/actions.hpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'control') 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 @@ auto count_state_before_speed(size_t count, T&& state, uint64_t speed) speed, state = std::forward(state)](auto& zone, auto& group) { - size_t numAtState = std::count_if( - group.begin(), - group.end(), - [&zone, &state](auto const& entry) + size_t numAtState = 0; + for (auto& entry : group) + { + try { - try - { - return zone.template getPropertyValue( - entry.first, - std::get(entry.second), - std::get(entry.second)) == state; - } - catch (const std::out_of_range& oore) + if (zone.template getPropertyValue( + entry.first, + std::get(entry.second), + std::get(entry.second)) == state) { - // Default to property not equal when not found - return false; + numAtState++; } - }); - if (numAtState >= count) - { - zone.setSpeed(speed); + } + 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)); -- cgit v1.2.1