diff options
author | Nathalie Lepine | 2020-10-15 14:47:35 +0000 |
---|---|---|
committer | Maxime Porhel | 2021-02-22 20:07:25 +0000 |
commit | b1fabbcaa831492adb60c741242991a7f8909491 (patch) | |
tree | 708f2ebfd6a125ff956bad04ea46dd3a330b0532 | |
parent | 54b85109d5d3f3e7700ebd7f95fe15bad5ab7909 (diff) | |
download | org.eclipse.sirius-b1fabbcaa831492adb60c741242991a7f8909491.tar.gz org.eclipse.sirius-b1fabbcaa831492adb60c741242991a7f8909491.tar.xz org.eclipse.sirius-b1fabbcaa831492adb60c741242991a7f8909491.zip |
[571400] Add a cache for ISequenceEvent.getLifeline
Bug: 571400
Cherry-picked-from: 567517
Change-Id: I8bf3ca2ba6c018aeb48caae85b8a94101aa5acab
Signed-off-by: Nathalie Lepine <nathalie.lepine@obeo.fr>
2 files changed, 38 insertions, 33 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/elements/AbstractSequenceNode.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/elements/AbstractSequenceNode.java index bd22834812..b48b1a2c51 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/elements/AbstractSequenceNode.java +++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/elements/AbstractSequenceNode.java @@ -27,6 +27,9 @@ import org.eclipse.sirius.ext.base.Options; * @author mporhel, pcdavid */ abstract class AbstractSequenceNode extends AbstractSequenceElement implements ISequenceNode { + + protected Option<Lifeline> cachedLifeline; + /** * Constructor. * @@ -77,7 +80,14 @@ abstract class AbstractSequenceNode extends AbstractSequenceElement implements I @Override public Option<Lifeline> getLifeline() { - return getParentLifeline(); + Option<Lifeline> result; + if (cachedLifeline != null) { + result = cachedLifeline; + } else { + result = getParentLifeline(); + cachedLifeline = result; + } + return result; } /** diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/elements/InstanceRole.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/elements/InstanceRole.java index bccd0d21bf..b4e1d7eb82 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/elements/InstanceRole.java +++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/elements/InstanceRole.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2015 THALES GLOBAL SERVICES and others. + * Copyright (c) 2010, 2021 THALES GLOBAL SERVICES and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -44,8 +44,7 @@ public class InstanceRole extends AbstractSequenceNode { public static final int VISUAL_ID = 2001; /** - * Predicate to check whether a Sirius DDiagramElement represents an - * instance role. + * Predicate to check whether a Sirius DDiagramElement represents an instance role. */ private enum SiriusElementPredicate implements Predicate<DDiagramElement> { INSTANCE; @@ -69,33 +68,28 @@ public class InstanceRole extends AbstractSequenceNode { } /** - * Returns a predicate to check whether a GMF View represents an instance - * role. + * Returns a predicate to check whether a GMF View represents an instance role. * - * @return a predicate to check whether a GMF View represents an instance - * role. + * @return a predicate to check whether a GMF View represents an instance role. */ public static Predicate<View> notationPredicate() { return new NotationPredicate(NotationPackage.eINSTANCE.getNode(), VISUAL_ID, InstanceRole.viewpointElementPredicate()); } /** - * Returns a predicate to check whether a Sirius DDiagramElement - * represents an instance role. + * Returns a predicate to check whether a Sirius DDiagramElement represents an instance role. * - * @return a predicate to check whether a Sirius DDiagramElement - * represents an instance role. + * @return a predicate to check whether a Sirius DDiagramElement represents an instance role. */ public static Predicate<DDiagramElement> viewpointElementPredicate() { return SiriusElementPredicate.INSTANCE; } /** - * Tests whether the instance role is explicitly created by a creation - * message, or if it starts from the beginning of the sequence. + * Tests whether the instance role is explicitly created by a creation message, or if it starts from the beginning + * of the sequence. * - * @return <code>true</code> if the instance role is explicitly created by a - * creation message. + * @return <code>true</code> if the instance role is explicitly created by a creation message. */ public boolean isExplicitlyCreated() { return getCreationMessage().some(); @@ -119,13 +113,20 @@ public class InstanceRole extends AbstractSequenceNode { @Override public Option<Lifeline> getLifeline() { - for (View child : Iterables.filter(getNotationView().getChildren(), View.class)) { - Option<Lifeline> lifeline = ISequenceElementAccessor.getLifeline(child); - if (lifeline.some()) { - return lifeline; + Option<Lifeline> result = Options.newNone(); + if (cachedLifeline != null) { + result = cachedLifeline; + } else { + for (View child : Iterables.filter(getNotationView().getChildren(), View.class)) { + Option<Lifeline> lifeline = ISequenceElementAccessor.getLifeline(child); + if (lifeline.some()) { + result = lifeline; + break; + } } + cachedLifeline = result; } - return Options.newNone(); + return result; } @Override @@ -139,11 +140,9 @@ public class InstanceRole extends AbstractSequenceNode { } /** - * Return the name of the DRepresentationElement associated to this Instance - * role. + * Return the name of the DRepresentationElement associated to this Instance role. * - * @return the name of the DRepresentationElement associated to this - * Instance role + * @return the name of the DRepresentationElement associated to this Instance role */ public String getName() { EObject targetElement = getNotationNode().getElement(); @@ -154,11 +153,9 @@ public class InstanceRole extends AbstractSequenceNode { } /** - * Return the background color of the style of the DRepresentationElement - * associated to this Instance role. + * Return the background color of the style of the DRepresentationElement associated to this Instance role. * - * @return the background color of the style of the DRepresentationElement - * associated to this Instance role. + * @return the background color of the style of the DRepresentationElement associated to this Instance role. */ public Option<RGBValues> getBackgroundColor() { EObject targetElement = getNotationNode().getElement(); @@ -169,11 +166,9 @@ public class InstanceRole extends AbstractSequenceNode { } /** - * Return the label color of the style of the DRepresentationElement - * associated to this Instance role. + * Return the label color of the style of the DRepresentationElement associated to this Instance role. * - * @return the label color of the style of the DRepresentationElement - * associated to this Instance role. + * @return the label color of the style of the DRepresentationElement associated to this Instance role. */ public Option<RGBValues> getLabelColor() { EObject targetElement = getNotationNode().getElement(); |