Skip to content

Commit

Permalink
Lazy creation of the list proxyInformation
Browse files Browse the repository at this point in the history
By doing that, when resources already linked are loaded from storage, no
memory needs to be allocated for the proxyInformation list.
  • Loading branch information
rubenporras committed Jan 17, 2025
1 parent 07b7598 commit d89d9fb
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public Set<String> get() {
return unresolveableProxies;
}

private ArrayList<Triple<EObject, EReference, INode>> proxyInformation = newArrayList();
private ArrayList<Triple<EObject, EReference, INode>> proxyInformation;

/**
* Returns the list of installed lazy linking proxies encoded as a {@link Triple} of the owning object,
Expand All @@ -512,6 +512,9 @@ public Set<String> get() {
* @since 2.23
*/
protected List<Triple<EObject, EReference, INode>> 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;
}
Expand All @@ -520,26 +523,28 @@ protected List<Triple<EObject, EReference, INode>> 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));
ArrayList<Triple<EObject, EReference, INode>> information = getLazyProxyInformation();
int index = information.size();
information.add(getParseResultWrapper().toProxyInformation(internalGetParseResult(), obj, ref, node));
return index;
}

/**
* @since 2.7
*/
public boolean hasLazyProxyInformation(int idx) {
return proxyInformation.get(idx) != null;
return getLazyProxyInformation().get(idx) != null;
}

/**
* @since 2.7
*/
public Triple<EObject,EReference,INode> getLazyProxyInformation(int idx) {
if (!hasLazyProxyInformation(idx)) {
Triple<EObject, EReference, INode> information = getLazyProxyInformation().get(idx);
if (information == null) {
throw new IllegalArgumentException("No proxy information for index '"+idx+"' available.");
}
return proxyInformation.get(idx);
return information;
}

/**
Expand All @@ -553,7 +558,9 @@ public Triple<EObject,EReference,INode> removeLazyProxyInformation(int idx) {
* @since 2.7
*/
public void clearLazyProxyInformation() {
proxyInformation = newArrayListWithCapacity(proxyInformation.size());
if (proxyInformation != null) {
proxyInformation.clear();
}
}

}

0 comments on commit d89d9fb

Please sign in to comment.