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

Add cache for (expensive) method getComposablePrototypes(Class)

Issue-Ref: 4106
Issue-Url: af3#4106



Signed-off-by: default avatarSimon Barner <barner@fortiss.org>
parent 25e90508
No related branches found
No related tags found
1 merge request!1334106: Add cache for (expensive) method getComposablePrototypes(Class)
Pipeline #27841 passed
Pipeline: maven-releng

#27842

    ...@@ -9,7 +9,7 @@ LibraryService.java a56e71191cd9bab5a6be461000e7e9b605c7b0db GREEN ...@@ -9,7 +9,7 @@ LibraryService.java a56e71191cd9bab5a6be461000e7e9b605c7b0db GREEN
    LoggingService.java da784259f7b456b54bf75c41ec268f64919ce78d GREEN LoggingService.java da784259f7b456b54bf75c41ec268f64919ce78d GREEN
    MigrationService.java 017c8438262065f663427a998536035bc7732fe1 GREEN MigrationService.java 017c8438262065f663427a998536035bc7732fe1 GREEN
    PersistencyService.java 621898863371959d822edcde0f83c8a4d2757972 GREEN PersistencyService.java 621898863371959d822edcde0f83c8a4d2757972 GREEN
    PrototypeService.java 04093ccaea091776e8ed6f8fc723a62e4619ddb6 GREEN PrototypeService.java 34fef95b51bb14f6c31144a9a92769141208c23a YELLOW
    ToolingKernelInternal.java f6e7114825748683c7f1d040b41ab854a6c4d79b GREEN ToolingKernelInternal.java f6e7114825748683c7f1d040b41ab854a6c4d79b GREEN
    TransformationService.java 64ee4fb5ccc623f8acfba20866fc2b0944c4adab GREEN TransformationService.java 64ee4fb5ccc623f8acfba20866fc2b0944c4adab GREEN
    TutorialService.java 675d3f365ce062869f86baa3779d50687674bda0 GREEN TutorialService.java 675d3f365ce062869f86baa3779d50687674bda0 GREEN
    ...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
    package org.fortiss.tooling.kernel.internal; package org.fortiss.tooling.kernel.internal;
    import static java.util.Collections.emptyList; import static java.util.Collections.emptyList;
    import static java.util.Collections.unmodifiableList;
    import static org.conqat.lib.commons.collections.CollectionUtils.asUnmodifiable; 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.getBundle;
    import static org.fortiss.tooling.kernel.utils.ExtensionPointUtils.getConfigurationElements; import static org.fortiss.tooling.kernel.utils.ExtensionPointUtils.getConfigurationElements;
    ...@@ -23,8 +24,10 @@ import static org.fortiss.tooling.kernel.utils.ExtensionPointUtils.loadClass; ...@@ -23,8 +24,10 @@ import static org.fortiss.tooling.kernel.utils.ExtensionPointUtils.loadClass;
    import static org.fortiss.tooling.kernel.utils.LoggingUtils.error; import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
    import java.util.ArrayList; import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.LinkedList; import java.util.LinkedList;
    import java.util.List; import java.util.List;
    import java.util.Map;
    import java.util.stream.Collectors; import java.util.stream.Collectors;
    import org.conqat.lib.commons.collections.UnmodifiableList; import org.conqat.lib.commons.collections.UnmodifiableList;
    ...@@ -71,6 +74,10 @@ public class PrototypeService implements IPrototypeService, IIntrospectiveKernel ...@@ -71,6 +74,10 @@ public class PrototypeService implements IPrototypeService, IIntrospectiveKernel
    /** The tutorial service instance. */ /** The tutorial service instance. */
    private ITutorialService tutorialService; private ITutorialService tutorialService;
    /** Cache for (expensive) {@link #getComposablePrototypes(Class)}. */
    private Map<Class<? extends EObject>, List<Prototype>> composablePrototypesCache =
    new HashMap<>();
    /** Initializes the service. */ /** Initializes the service. */
    public void initializeService() { public void initializeService() {
    setupPrototypes(); setupPrototypes();
    ...@@ -189,14 +196,20 @@ public class PrototypeService implements IPrototypeService, IIntrospectiveKernel ...@@ -189,14 +196,20 @@ public class PrototypeService implements IPrototypeService, IIntrospectiveKernel
    /** {@inheritDoc} */ /** {@inheritDoc} */
    @Override @Override
    public List<Prototype> getComposablePrototypes(Class<? extends EObject> modelElementType) { public List<Prototype> getComposablePrototypes(Class<? extends EObject> modelElementType) {
    List<Prototype> composablePrototypes = composablePrototypesCache.get(modelElementType);
    if(composablePrototypes != null) {
    return composablePrototypes;
    }
    IElementCompositorService ecs = IElementCompositorService.getInstance(); IElementCompositorService ecs = IElementCompositorService.getInstance();
    List<Prototype> result = new LinkedList<Prototype>(); composablePrototypes = new LinkedList<Prototype>();
    for(Prototype prototype : getAllPrototypes()) { for(Prototype prototype : getAllPrototypes()) {
    if(ecs.canComposePrototype(modelElementType, prototype)) { if(ecs.canComposePrototype(modelElementType, prototype)) {
    result.add(prototype); composablePrototypes.add(prototype);
    } }
    } }
    return result; composablePrototypes = unmodifiableList(composablePrototypes);
    composablePrototypesCache.put(modelElementType, composablePrototypes);
    return composablePrototypes;
    } }
    /** {@inheritDoc} */ /** {@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