From 0945f1df4e7a84039755d95541f35592cb441062 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Wed, 5 Feb 2020 17:11:25 +1300 Subject: [PATCH] CellML support: improved the speed with which we update our runtime (#2285). --- .../CellMLSupport/src/cellmlfileruntime.cpp | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/plugins/support/CellMLSupport/src/cellmlfileruntime.cpp b/src/plugins/support/CellMLSupport/src/cellmlfileruntime.cpp index 0373fa6119..6106404fcd 100644 --- a/src/plugins/support/CellMLSupport/src/cellmlfileruntime.cpp +++ b/src/plugins/support/CellMLSupport/src/cellmlfileruntime.cpp @@ -309,36 +309,37 @@ void CellmlFileRuntime::update(CellmlFile *pCellmlFile, bool pAll) // Go through the variables defined or referenced in our main CellML // file and do a mapping between the source of that variable and that // variable itself - // Note: indeed, when it comes to (real) CellML 1.1 files (i.e. CellML - // 1.1 files that import some components), we only want to list + // Note: indeed, when a CellML file has imports, we only want to list // the parameters that are either defined or referenced in our // main CellML file. Not only does it make sense, but also only // the parameters listed in a main CellML file can be referenced // in a SED-ML file... + bool hasImports = model->imports()->length() != 0; QMap mainVariables; QList realMainVariables; ObjRef localComponentsIter = model->localComponents()->iterateComponents(); - for (ObjRef component = localComponentsIter->nextComponent(); - component != nullptr; component = localComponentsIter->nextComponent()) { - ObjRef variablesIter = component->variables()->iterateVariables(); + if (hasImports) { + for (ObjRef component = localComponentsIter->nextComponent(); + component != nullptr; component = localComponentsIter->nextComponent()) { + ObjRef variablesIter = component->variables()->iterateVariables(); - for (ObjRef variable = variablesIter->nextVariable(); - variable != nullptr; variable = variablesIter->nextVariable()) { - ObjRef sourceVariable = variable->sourceVariable(); + for (ObjRef variable = variablesIter->nextVariable(); + variable != nullptr; variable = variablesIter->nextVariable()) { + ObjRef sourceVariable = variable->sourceVariable(); - mainVariables.insert(sourceVariable, variable); + mainVariables.insert(sourceVariable, variable); - // In CellML 1.0 models / some CellML 1.1 models, the source - // variable is / may be defined in the main CellML file and may - // be used (and therefore referenced) in different places in - // that same main CellML file, in which case we need to keep - // track of the real main variable, which is the one which - // source variable is the same + // The source variable may be defined in the main CellML + // file and may be used (and therefore referenced) in + // different places in that same main CellML file, in which + // case we need to keep track of the real main variable, + // which is the one which source variable is the same - if (variable == sourceVariable) { - realMainVariables << variable; + if (variable == sourceVariable) { + realMainVariables << variable; + } } } } @@ -357,7 +358,7 @@ void CellmlFileRuntime::update(CellmlFile *pCellmlFile, bool pAll) // our main CellML file, if it has imports ObjRef variable = computationTarget->variable(); - iface::cellml_api::CellMLVariable *mainVariable = realMainVariables.contains(variable)? + iface::cellml_api::CellMLVariable *mainVariable = (!hasImports || realMainVariables.contains(variable))? variable.getPointer(): mainVariables.value(variable);