Skip to content
Snippets Groups Projects
Commit 43eb3a5f authored by Simon Barner's avatar Simon Barner
Browse files

Merge branch '4106' into 'master'

4106: Add cache for (expensive) method getComposablePrototypes(Class)

See merge request !133
parents 25e90508 ef9acb6c
No related branches found
No related tags found
1 merge request!1334106: Add cache for (expensive) method getComposablePrototypes(Class)
......@@ -9,7 +9,7 @@ LibraryService.java a56e71191cd9bab5a6be461000e7e9b605c7b0db GREEN
LoggingService.java da784259f7b456b54bf75c41ec268f64919ce78d GREEN
MigrationService.java 017c8438262065f663427a998536035bc7732fe1 GREEN
PersistencyService.java 621898863371959d822edcde0f83c8a4d2757972 GREEN
PrototypeService.java 04093ccaea091776e8ed6f8fc723a62e4619ddb6 GREEN
PrototypeService.java 34fef95b51bb14f6c31144a9a92769141208c23a GREEN
ToolingKernelInternal.java f6e7114825748683c7f1d040b41ab854a6c4d79b GREEN
TransformationService.java 64ee4fb5ccc623f8acfba20866fc2b0944c4adab GREEN
TutorialService.java 675d3f365ce062869f86baa3779d50687674bda0 GREEN
......@@ -16,6 +16,7 @@
package org.fortiss.tooling.kernel.internal;
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableList;
import static org.conqat.lib.commons.collections.CollectionUtils.asUnmodifiable;
import static org.fortiss.tooling.kernel.utils.ExtensionPointUtils.getBundle;
import static org.fortiss.tooling.kernel.utils.ExtensionPointUtils.getConfigurationElements;
......@@ -23,8 +24,10 @@ import static org.fortiss.tooling.kernel.utils.ExtensionPointUtils.loadClass;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.conqat.lib.commons.collections.UnmodifiableList;
......@@ -71,6 +74,10 @@ public class PrototypeService implements IPrototypeService, IIntrospectiveKernel
/** The tutorial service instance. */
private ITutorialService tutorialService;
/** Cache for (expensive) {@link #getComposablePrototypes(Class)}. */
private Map<Class<? extends EObject>, List<Prototype>> composablePrototypesCache =
new HashMap<>();
/** Initializes the service. */
public void initializeService() {
setupPrototypes();
......@@ -189,14 +196,20 @@ public class PrototypeService implements IPrototypeService, IIntrospectiveKernel
/** {@inheritDoc} */
@Override
public List<Prototype> getComposablePrototypes(Class<? extends EObject> modelElementType) {
List<Prototype> composablePrototypes = composablePrototypesCache.get(modelElementType);
if(composablePrototypes != null) {
return composablePrototypes;
}
IElementCompositorService ecs = IElementCompositorService.getInstance();
List<Prototype> result = new LinkedList<Prototype>();
composablePrototypes = new LinkedList<Prototype>();
for(Prototype prototype : getAllPrototypes()) {
if(ecs.canComposePrototype(modelElementType, prototype)) {
result.add(prototype);
composablePrototypes.add(prototype);
}
}
return result;
composablePrototypes = unmodifiableList(composablePrototypes);
composablePrototypesCache.put(modelElementType, composablePrototypes);
return composablePrototypes;
}
/** {@inheritDoc} */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment