forked from qt-creator/qt-creator
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:
@@ -10,33 +10,17 @@ namespace Tasking {
|
|||||||
|
|
||||||
static Group conditionRecipe(const Storage<bool> &bodyExecutedStorage, const ConditionData &condition)
|
static Group conditionRecipe(const Storage<bool> &bodyExecutedStorage, const ConditionData &condition)
|
||||||
{
|
{
|
||||||
const Storage<bool> doExecuteBodyStorage(true);
|
|
||||||
|
|
||||||
const auto onSetup = [bodyExecutedStorage] {
|
const auto onSetup = [bodyExecutedStorage] {
|
||||||
return *bodyExecutedStorage ? SetupResult::StopWithSuccess : SetupResult::Continue;
|
return *bodyExecutedStorage ? SetupResult::StopWithSuccess : SetupResult::Continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto onConditionDone = [doExecuteBodyStorage](DoneWith result) {
|
const auto onBodyDone = [bodyExecutedStorage] { *bodyExecutedStorage = true; };
|
||||||
*doExecuteBodyStorage = result == DoneWith::Success;
|
|
||||||
return DoneResult::Success;
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto onContinuationSetup = [doExecuteBodyStorage, bodyExecutedStorage] {
|
const Group bodyTask { condition.m_body, onGroupDone(onBodyDone) };
|
||||||
*bodyExecutedStorage = *doExecuteBodyStorage;
|
|
||||||
return *doExecuteBodyStorage ? SetupResult::Continue : SetupResult::StopWithSuccess;
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
doExecuteBodyStorage,
|
|
||||||
onGroupSetup(onSetup),
|
onGroupSetup(onSetup),
|
||||||
condition.m_condition ? Group {
|
condition.m_condition ? Group{ !*condition.m_condition || bodyTask } : bodyTask
|
||||||
*condition.m_condition,
|
|
||||||
onGroupDone(onConditionDone)
|
|
||||||
} : nullItem,
|
|
||||||
Group {
|
|
||||||
onGroupSetup(onContinuationSetup),
|
|
||||||
condition.m_body
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user