X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Fmodule%2FLazyModule.java;h=ce3b7cc5fd22ff49fd4b2a01c5205d3647c2f82e;hp=6daef2b172bd27c0c8febf7dd3359b25b4dd190e;hb=9ea5cf59a4d87c3db3a486e86d7b54efffd5516d;hpb=3e4f9c4926e49efb26785e47a234de013a7ef15e diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/LazyModule.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/LazyModule.java index 6daef2b17..ce3b7cc5f 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/LazyModule.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/LazyModule.java @@ -3,6 +3,8 @@ package org.simantics.scl.compiler.module; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; import org.simantics.scl.compiler.constants.Constant; import org.simantics.scl.compiler.elaboration.chr.CHRRuleset; @@ -25,10 +27,10 @@ import gnu.trove.map.hash.THashMap; public abstract class LazyModule implements Module { - String moduleName; - private THashMap values = new THashMap(); - private THashMap relations = new THashMap(); - private THashMap entityTypes = new THashMap(); + private final String moduleName; + private final ConcurrentHashMap values = new ConcurrentHashMap(); + private final ConcurrentHashMap relations = new ConcurrentHashMap(); + private final ConcurrentHashMap entityTypes = new ConcurrentHashMap(); protected abstract SCLValue createValue(String name); @@ -62,15 +64,11 @@ public abstract class LazyModule implements Module { public void findValuesForPrefix(final Collection values, final String prefix) { } + private final Function createValue = this::createValue; + @Override public SCLValue getValue(String name) { - if(values.containsKey(name)) - return values.get(name); - else { - SCLValue value = createValue(name); - values.put(name, value); - return value; - } + return values.computeIfAbsent(name, createValue); } @Override @@ -78,24 +76,16 @@ public abstract class LazyModule implements Module { return null; } + private final Function createRelation = this::createRelation; + public SCLRelation getRelation(String name) { - if(relations.containsKey(name)) - return relations.get(name); - else { - SCLRelation relation = createRelation(name); - relations.put(name, relation); - return relation; - } + return relations.computeIfAbsent(name, createRelation); } + private final Function createEntityType = this::createEntityType; + public SCLEntityType getEntityType(String name) { - if(entityTypes.containsKey(name)) - return entityTypes.get(name); - else { - SCLEntityType entityType = createEntityType(name); - entityTypes.put(name, entityType); - return entityType; - } + return entityTypes.computeIfAbsent(name, createEntityType); } @Override