From dccf6f16f5cec7d7ed94c4ffa028687c58cbfea5 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 8 Jun 2018 17:56:23 -0400 Subject: [PATCH] [libcalamaresui] Lambdas are fun, but not always the solution --- .../modulesystem/ModuleManager.cpp | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/libcalamaresui/modulesystem/ModuleManager.cpp b/src/libcalamaresui/modulesystem/ModuleManager.cpp index df77c5602..317ca884f 100644 --- a/src/libcalamaresui/modulesystem/ModuleManager.cpp +++ b/src/libcalamaresui/modulesystem/ModuleManager.cpp @@ -154,6 +154,26 @@ ModuleManager::moduleInstance( const QString& instanceKey ) } +/** + * @brief Search a list of instance descriptions for one matching @p module and @p id + * + * @return -1 on failure, otherwise index of the instance that matches. + */ +static int findCustomInstance( const Settings::InstanceDescriptionList& customInstances, + const QString& module, + const QString& id ) +{ + for ( int i = 0; i < customInstances.count(); ++i ) + { + const auto& thisInstance = customInstances[ i ]; + if ( thisInstance.value( "module" ) == module && + thisInstance.value( "id" ) == id ) + return i; + } + return -1; +} + + void ModuleManager::loadModules() { @@ -196,25 +216,11 @@ ModuleManager::loadModules() return; } - auto findCustomInstance = - [ customInstances ]( const QString& module, - const QString& id) -> int - { - for ( int i = 0; i < customInstances.count(); ++i ) - { - auto thisInstance = customInstances[ i ]; - if ( thisInstance.value( "module" ) == module && - thisInstance.value( "id" ) == id ) - return i; - } - return -1; - }; - if ( moduleName != instanceId ) //means this is a custom instance { - if ( findCustomInstance( moduleName, instanceId ) > -1 ) + if ( int found = findCustomInstance( customInstances, moduleName, instanceId ) > -1 ) { - configFileName = customInstances[ findCustomInstance( moduleName, instanceId ) ].value( "config" ); + configFileName = customInstances[ found ].value( "config" ); } else //ought to be a custom instance, but cannot find instance entry {