From 55360366029b8e3fe70b432d54f3acf1b58ecffe Mon Sep 17 00:00:00 2001 From: Konstantin Kolmar Date: Tue, 29 Aug 2023 08:30:53 +0200 Subject: [PATCH] Improved performance of build dependencies --- .../org/mps_cli/model/SRepository.groovy | 51 +++++++++++++------ 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/mps-cli-gradle-plugin/plugin/src/main/groovy/org/mps_cli/model/SRepository.groovy b/mps-cli-gradle-plugin/plugin/src/main/groovy/org/mps_cli/model/SRepository.groovy index 36538b5..1e483b5 100644 --- a/mps-cli-gradle-plugin/plugin/src/main/groovy/org/mps_cli/model/SRepository.groovy +++ b/mps-cli-gradle-plugin/plugin/src/main/groovy/org/mps_cli/model/SRepository.groovy @@ -1,35 +1,54 @@ package org.mps_cli.model class SRepository { - def List modules = [] - def List languages = [] + List modules = [] + List languages = [] + + private List allModelsCache = null + private List allNodesCache = null + private Map id2modelsCache = null + private Map id2ModulesCache = null List allModels() { - def models = [] - modules.each { sol -> - models.addAll(sol.models) + if (allModelsCache == null) { + allModelsCache = modules.collectMany { it.models } } - models + allModelsCache } - List findModelByName(String modelName) { - allModels().findAll {it.name.equals(modelName) } + List allNodes() { + if (allNodesCache == null) { + allNodesCache = allModels().collectMany { it.allNodes } + } + allNodesCache } Map id2models() { - allModels().collectEntries {[it.modelId, it]} + if (id2modelsCache == null) { + id2modelsCache = allModels().collectEntries {[it.modelId, it] } + } + id2modelsCache } Map id2modules() { - modules.collectEntries {[it.moduleId, it]} + if (id2ModulesCache == null) { + id2ModulesCache = modules.collectEntries {[it.moduleId, it] } + } + id2ModulesCache } - List allNodes() { - def nodes = [] - allModels().each { mod -> - nodes.addAll(mod.allNodes) - } - nodes + List findModelByName(String modelName) { + allModels().findAll { (it.name == modelName) } + } + + SModel findModelByRealPath(String realPath) { + if (realPath == null) return null + allModels().find { (it.pathToModelFile == realPath) } + } + + SModuleBase findModuleByRealPath(String realPath) { + if (realPath == null) return null + modules.find { (it.pathToModuleFile == realPath) } } List nodesOfConcept(String fullyQualifiedConceptName) {