Skip to content

Commit c6f4f40

Browse files
committed
perf: replace recursion with iteration
1 parent 20f2501 commit c6f4f40

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/resource/persistence/ProxyCompositeNode.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.io.IOException;
1414
import java.util.ArrayList;
1515
import java.util.List;
16+
import java.util.Stack;
1617

1718
import org.eclipse.emf.common.notify.Adapter;
1819
import org.eclipse.emf.common.notify.Notification;
@@ -87,17 +88,23 @@ static void installProxyNodeModel(final Resource resource) {
8788
}
8889

8990
private static ProxyCompositeNode installProxyNodeModel(final EObject eObject, final List<EObject> map) {
90-
ProxyCompositeNode result = new ProxyCompositeNode();
91-
eObject.eAdapters().add(result);
91+
Stack<EObject> stack = new Stack<>(); // NOPMD LooseCoupling
92+
stack.push(eObject);
93+
ProxyCompositeNode rootComposite = new ProxyCompositeNode();
94+
eObject.eAdapters().add(rootComposite);
9295
map.add(eObject);
9396

94-
for (FeatureIterator<EObject> it = (FeatureIterator<EObject>) eObject.eContents().iterator(); it.hasNext();) {
95-
EObject child = it.next();
96-
if (!it.feature().isTransient()) {
97-
installProxyNodeModel(child, map);
97+
while (!stack.isEmpty()) {
98+
for (FeatureIterator<EObject> it = (FeatureIterator<EObject>) stack.pop().eContents().reversed().iterator(); it.hasNext();) {
99+
EObject child = it.next();
100+
if (!it.feature().isTransient()) {
101+
child.eAdapters().add(new ProxyCompositeNode());
102+
map.add(child);
103+
stack.push(child);
104+
}
98105
}
99106
}
100-
return result;
107+
return rootComposite;
101108
}
102109

103110
/**

0 commit comments

Comments
 (0)