TaskTree: Simplify conditionalRecipe()

Eliminate the internal Storage object.
Use logical operators and rely on short-circuiting behavior.

Change-Id: I13dcd39f2c7c5d2c40dc228ccff6d5dcdbd42394
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2024-09-13 21:48:02 +02:00
parent 9a119af83a
commit db33b9e104

View File

@@ -10,33 +10,17 @@ namespace Tasking {
static Group conditionRecipe(const Storage<bool> &bodyExecutedStorage, const ConditionData &condition)
{
const Storage<bool> doExecuteBodyStorage(true);
const auto onSetup = [bodyExecutedStorage] {
return *bodyExecutedStorage ? SetupResult::StopWithSuccess : SetupResult::Continue;
};
const auto onConditionDone = [doExecuteBodyStorage](DoneWith result) {
*doExecuteBodyStorage = result == DoneWith::Success;
return DoneResult::Success;
};
const auto onBodyDone = [bodyExecutedStorage] { *bodyExecutedStorage = true; };
const auto onContinuationSetup = [doExecuteBodyStorage, bodyExecutedStorage] {
*bodyExecutedStorage = *doExecuteBodyStorage;
return *doExecuteBodyStorage ? SetupResult::Continue : SetupResult::StopWithSuccess;
};
const Group bodyTask { condition.m_body, onGroupDone(onBodyDone) };
return {
doExecuteBodyStorage,
onGroupSetup(onSetup),
condition.m_condition ? Group {
*condition.m_condition,
onGroupDone(onConditionDone)
} : nullItem,
Group {
onGroupSetup(onContinuationSetup),
condition.m_body
}
condition.m_condition ? Group{ !*condition.m_condition || bodyTask } : bodyTask
};
}