From 2046e4669dc7c47d1791387b641b6247c2b9e7a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Porras=20Campo?= Date: Fri, 17 Jan 2025 10:17:14 +0100 Subject: [PATCH] Lazy creation of the list proxyInformation By doing that, when resources already linked are loaded from storage, no memory needs to be allocated for the proxyInformation list. --- .../linking/lazy/LazyLinkingResource.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/org.eclipse.xtext/src/org/eclipse/xtext/linking/lazy/LazyLinkingResource.java b/org.eclipse.xtext/src/org/eclipse/xtext/linking/lazy/LazyLinkingResource.java index 74ead664b44..e1a7bb92325 100644 --- a/org.eclipse.xtext/src/org/eclipse/xtext/linking/lazy/LazyLinkingResource.java +++ b/org.eclipse.xtext/src/org/eclipse/xtext/linking/lazy/LazyLinkingResource.java @@ -503,7 +503,7 @@ public Set get() { return unresolveableProxies; } - private ArrayList> proxyInformation = newArrayList(); + private ArrayList> proxyInformation; /** * Returns the list of installed lazy linking proxies encoded as a {@link Triple} of the owning object, @@ -512,6 +512,9 @@ public Set get() { * @since 2.23 */ protected List> getLazyProxyInformation() { + if (proxyInformation == null) { + proxyInformation = newArrayList(); + } // Make the list available to sub-types in a modifiable way such that they can work with it more efficiently return proxyInformation; } @@ -520,8 +523,9 @@ protected List> getLazyProxyInformation() { * @since 2.7 */ public int addLazyProxyInformation(EObject obj, EReference ref, INode node) { - int index = proxyInformation.size(); - proxyInformation.add(getParseResultWrapper().toProxyInformation(internalGetParseResult(), obj, ref, node)); + List> information = getLazyProxyInformation(); + int index = information.size(); + information.add(getParseResultWrapper().toProxyInformation(internalGetParseResult(), obj, ref, node)); return index; } @@ -529,17 +533,18 @@ public int addLazyProxyInformation(EObject obj, EReference ref, INode node) { * @since 2.7 */ public boolean hasLazyProxyInformation(int idx) { - return proxyInformation.get(idx) != null; + return getLazyProxyInformation().get(idx) != null; } /** * @since 2.7 */ public Triple getLazyProxyInformation(int idx) { - if (!hasLazyProxyInformation(idx)) { + Triple information = getLazyProxyInformation().get(idx); + if (information == null) { throw new IllegalArgumentException("No proxy information for index '"+idx+"' available."); } - return proxyInformation.get(idx); + return information; } /** @@ -553,7 +558,9 @@ public Triple removeLazyProxyInformation(int idx) { * @since 2.7 */ public void clearLazyProxyInformation() { - proxyInformation = newArrayListWithCapacity(proxyInformation.size()); + if (proxyInformation != null) { + proxyInformation.clear(); + } } }