Skip to content

Commit

Permalink
Improved performance of build dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
kolmar committed Aug 29, 2023
1 parent 5a9e09e commit 5536036
Showing 1 changed file with 35 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,35 +1,54 @@
package org.mps_cli.model

class SRepository {
def List<SModuleBase> modules = []
def List<SLanguage> languages = []
List<SModuleBase> modules = []
List<SLanguage> languages = []

private List<SModel> allModelsCache = null
private List<SNode> allNodesCache = null
private Map<String, SModel> id2modelsCache = null
private Map<String, SModuleBase> id2ModulesCache = null

List<SModel> allModels() {
def models = []
modules.each { sol ->
models.addAll(sol.models)
if (allModelsCache == null) {
allModelsCache = modules.collectMany { it.models }
}
models
allModelsCache
}

List<SModel> findModelByName(String modelName) {
allModels().findAll {it.name.equals(modelName) }
List<SNode> allNodes() {
if (allNodesCache == null) {
allNodesCache = allModels().collectMany { it.allNodes }
}
allNodesCache
}

Map<String, SModel> id2models() {
allModels().collectEntries {[it.modelId, it]}
if (id2modelsCache == null) {
id2modelsCache = allModels().collectEntries {[it.modelId, it] }
}
id2modelsCache
}

Map<String, SModuleBase> id2modules() {
modules.collectEntries {[it.moduleId, it]}
if (id2ModulesCache == null) {
id2ModulesCache = modules.collectEntries {[it.moduleId, it] }
}
id2ModulesCache
}

List<SNode> allNodes() {
def nodes = []
allModels().each { mod ->
nodes.addAll(mod.allNodes)
}
nodes
List<SModel> 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<SNode> nodesOfConcept(String fullyQualifiedConceptName) {
Expand Down

0 comments on commit 5536036

Please sign in to comment.