diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/GMFHelper.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/GMFHelper.java index 7ff0908f58..da2c1c5a8c 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/GMFHelper.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/GMFHelper.java @@ -16,6 +16,7 @@ import java.net.MalformedURLException; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -132,6 +133,8 @@ public final class GMFHelper { */ private static final int ICON_TEXT_GAP = 3; + private static Map boundsCache = new HashMap<>(); + private GMFHelper() { // Helper to not instantiate } @@ -617,9 +620,21 @@ public static Rectangle getAbsoluteBounds(Node node, boolean insetsAware, boolea * @return the absolute bounds of the node relative to the origin (Diagram) */ public static Rectangle getAbsoluteBounds(Node node, boolean insetsAware, boolean boxForConnection, boolean recursiveGetBounds) { - Point location = getAbsoluteLocation(node, insetsAware); - Rectangle bounds = getBounds(node, false, false, boxForConnection, recursiveGetBounds, location); - return new PrecisionRectangle(location.preciseX(), location.preciseY(), bounds.preciseWidth(), bounds.preciseHeight()); + if (!recursiveGetBounds) { + boundsCache.clear(); + } + Rectangle result; + if (boundsCache.containsKey(node)) { + result = boundsCache.get(node); + } else { + Point location = getAbsoluteLocation(node, insetsAware); + Rectangle bounds = getBounds(node, false, false, boxForConnection, recursiveGetBounds, location); + result = new PrecisionRectangle(location.preciseX(), location.preciseY(), bounds.preciseWidth(), bounds.preciseHeight()); + if (recursiveGetBounds) { + boundsCache.put(node, result); + } + } + return result; } /**