Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1efc4849 authored by Tom Cherry's avatar Tom Cherry
Browse files

init: make CheckPropertyTriggers() more efficient

Previously CheckPropertyTriggers() tried to do the entire property
triggers check with one loop.  However, that would require calling
GetProperty() on all properties for all triggers just in case the
property that is being set is used by a given trigger.

This change first checks that the property being set exists in each
trigger and that its value is set such that the trigger would be
triggered, only then does it check that other property triggers are
set to the right value.

Bug: 143922756
Test: boot
Test: substantially fewer GetProperty() calls from
      CheckPropertyTriggers()

Change-Id: I0228cf47328b31963eaf3fc689fb60f711532df4
parent e91c76b2
Loading
Loading
Loading
Loading
+14 −11
Original line number Diff line number Diff line
@@ -180,21 +180,24 @@ void Action::ExecuteCommand(const Command& command) const {
// It takes an optional (name, value) pair, which if provided must
// be present in property_triggers_; it skips the check of the current
// property value for this pair.
bool Action::CheckPropertyTriggers(const std::string& name,
                                   const std::string& value) const {
bool Action::CheckPropertyTriggers(const std::string& name, const std::string& value) const {
    if (property_triggers_.empty()) {
        return true;
    }

    bool found = name.empty();
    for (const auto& [trigger_name, trigger_value] : property_triggers_) {
        if (trigger_name == name) {
    if (!name.empty()) {
        auto it = property_triggers_.find(name);
        if (it == property_triggers_.end()) {
            return false;
        }
        const auto& trigger_value = it->second;
        if (trigger_value != "*" && trigger_value != value) {
            return false;
            } else {
                found = true;
        }
        } else {
    }

    for (const auto& [trigger_name, trigger_value] : property_triggers_) {
        if (trigger_name != name) {
            std::string prop_value = android::base::GetProperty(trigger_name, "");
            if (trigger_value == "*" && !prop_value.empty()) {
                continue;
@@ -202,7 +205,7 @@ bool Action::CheckPropertyTriggers(const std::string& name,
            if (trigger_value != prop_value) return false;
        }
    }
    return found;
    return true;
}

bool Action::CheckEvent(const EventTrigger& event_trigger) const {