From 3849cd7b1848e9354917e7b3bc9dc6e776b27f3b Mon Sep 17 00:00:00 2001 From: Maxime Porhel Date: Fri, 16 Jan 2015 17:19:07 +0100 Subject: [458973] Minimize event ends computation during layout Compute event ends only once and not three times. We did not choose to introduce two new constructors to indicate the allEventEnds at creation because the chosen way allows other subclassers to provide a way to compute differently the getAllEventEnds and to be sure they will be called/computed during execute. Bug: 458973 Cherry-picked-from: 457678 Change-Id: Ibd6cc121067ad1abfb1c4f65084d1b48273f60a3 Signed-off-by: Maxime Porhel --- .../operation/RefreshGraphicalOrderingOperation.java | 13 ++++++++++++- .../operation/RefreshSemanticOrderingsOperation.java | 13 ++++++++++++- .../internal/refresh/RefreshLayoutCommand.java | 20 ++++++++++++++++++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/operation/RefreshGraphicalOrderingOperation.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/operation/RefreshGraphicalOrderingOperation.java index d23ec4f782..b77c607a5e 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/operation/RefreshGraphicalOrderingOperation.java +++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/operation/RefreshGraphicalOrderingOperation.java @@ -98,7 +98,7 @@ public class RefreshGraphicalOrderingOperation extends AbstractModelChangeOperat } } }; - List allEnds = Lists.newArrayList(Iterables.filter(RefreshOrderingHelper.getAllEventEnds(sequenceDiagram), isValidEnd)); + List allEnds = Lists.newArrayList(Iterables.filter(getAllEventEnds(), isValidEnd)); Collections.sort(allEnds, Ordering.natural().onResultOf(new Function() { @Override public Integer apply(EventEnd input) { @@ -112,6 +112,17 @@ public class RefreshGraphicalOrderingOperation extends AbstractModelChangeOperat return RefreshOrderingHelper.updateIfNeeded(graphicalOrdering.getEventEnds(), allEnds); } + /** + * Returns all the event ends of the current Sequence diagram. + * + * The default implementation does the computation on each call, subclasses may override this method to change this behavior. + * + * @return an Iterable with all event ends. + */ + protected Iterable getAllEventEnds() { + return RefreshOrderingHelper.getAllEventEnds(sequenceDiagram); + } + /** * Custom vertical function which do not return the real location of an * event end but allow to correctly order event end from logically diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/operation/RefreshSemanticOrderingsOperation.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/operation/RefreshSemanticOrderingsOperation.java index dfededfa2d..4e521798bb 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/operation/RefreshSemanticOrderingsOperation.java +++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/operation/RefreshSemanticOrderingsOperation.java @@ -95,10 +95,21 @@ public class RefreshSemanticOrderingsOperation extends AbstractModelChangeOperat * @return true if there is changes during this refresh, false otherwise. */ private boolean refreshGlobalOrdering(EventEndsOrdering semanticOrdering) { - Iterable allEnds = RefreshOrderingHelper.getAllEventEnds(sequenceDDiagram); + Iterable allEnds = getAllEventEnds(); return RefreshOrderingHelper.updateIfNeeded(semanticOrdering.getEventEnds(), computeEventEndsOrdering(semanticOrdering, allEnds)); } + /** + * Returns all the event ends of the current Sequence diagram. + * + * The default implementation does the computation on each call, subclasses may override this method to change this behavior. + * + * @return an Iterable with all event ends. + */ + protected Iterable getAllEventEnds() { + return RefreshOrderingHelper.getAllEventEnds(sequenceDDiagram); + } + private List computeEventEndsOrdering(EventEndsOrdering semanticOrdering, Iterable allEnds) { Map index = Maps.newHashMap(); for (EventEnd eventEnd : allEnds) { diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/refresh/RefreshLayoutCommand.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/refresh/RefreshLayoutCommand.java index f539d8e1ff..929a716f9c 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/refresh/RefreshLayoutCommand.java +++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/refresh/RefreshLayoutCommand.java @@ -21,6 +21,8 @@ import org.eclipse.sirius.diagram.sequence.business.internal.elements.SequenceDi import org.eclipse.sirius.diagram.sequence.business.internal.operation.RefreshGraphicalOrderingOperation; import org.eclipse.sirius.diagram.sequence.business.internal.operation.RefreshSemanticOrderingsOperation; import org.eclipse.sirius.diagram.sequence.business.internal.operation.SynchronizeGraphicalOrderingOperation; +import org.eclipse.sirius.diagram.sequence.business.internal.ordering.RefreshOrderingHelper; +import org.eclipse.sirius.diagram.sequence.ordering.EventEnd; import org.eclipse.sirius.diagram.ui.business.internal.operation.AbstractModelChangeOperation; import org.eclipse.sirius.ui.tools.api.profiler.SiriusTasks; @@ -72,11 +74,25 @@ public class RefreshLayoutCommand extends RecordingCommand { * Everything has been committed, so we should be in a stable state * where it is safe to refresh both orderings. */ - AbstractModelChangeOperation refreshSemanticOrderingOperation = new RefreshSemanticOrderingsOperation(sequenceDDiagram); + + // Compute only once (and not three times) the event ends. + final Iterable allEventEnds = RefreshOrderingHelper.getAllEventEnds(sequenceDDiagram); + + AbstractModelChangeOperation refreshSemanticOrderingOperation = new RefreshSemanticOrderingsOperation(sequenceDDiagram) { + @Override + protected Iterable getAllEventEnds() { + return allEventEnds; + } + }; if (refreshSemanticOrderingOperation.execute()) { sequenceDiagram.clearOrderedCaches(); } - AbstractModelChangeOperation refreshGraphicalOrderingOperation = new RefreshGraphicalOrderingOperation(sequenceDiagram); + AbstractModelChangeOperation refreshGraphicalOrderingOperation = new RefreshGraphicalOrderingOperation(sequenceDiagram) { + @Override + protected Iterable getAllEventEnds() { + return allEventEnds; + } + }; if (refreshGraphicalOrderingOperation.execute()) { sequenceDiagram.clearOrderedCaches(); } -- cgit v1.2.3