diff options
author | Nathalie Lepine | 2020-10-15 14:47:35 +0000 |
---|---|---|
committer | Maxime Porhel | 2020-10-23 13:59:28 +0000 |
commit | 0b606e0152a61d12e6b4ccebda5e446ac6a1f177 (patch) | |
tree | c6e0dbb8f43611438206c53a0385203493dffd7e | |
parent | bb7d9cff5d5d7f59c50f80147bb93cbe4f8710f9 (diff) | |
download | org.eclipse.sirius-0b606e0152a61d12e6b4ccebda5e446ac6a1f177.tar.gz org.eclipse.sirius-0b606e0152a61d12e6b4ccebda5e446ac6a1f177.tar.xz org.eclipse.sirius-0b606e0152a61d12e6b4ccebda5e446ac6a1f177.zip |
[567517] Add a cache for ISequenceEvent.getLifeline
Bug: 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 73c17c1927..961ed35a91 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 @@ -29,6 +29,9 @@ import org.eclipse.sirius.ext.base.Options; * @author mporhel, pcdavid */ abstract class AbstractSequenceNode extends AbstractSequenceElement implements ISequenceNode { + + protected Option<Lifeline> cachedLifeline; + /** * Constructor. * @@ -79,7 +82,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 004126201c..5c0f1a6309 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, 2020 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -46,8 +46,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; @@ -71,33 +70,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(); @@ -121,13 +115,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 @@ -141,11 +142,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(); @@ -156,11 +155,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(); @@ -171,11 +168,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(); |