Skip to content

Commit 2655fd6

Browse files
ptzieglerazoitl
authored andcommitted
Replace RunnableChain in DeferredUpdateManager with List - Bug 281327
In the class org.eclipse.draw2d.DeferredUpdateManager, Runnables are queued using a special inner class RunnableChain which basically produces a linked list of Runnables. When run is called on the head of the linked list, first run of its next element is called an then run on the runnable of the element itself. This produces very large stacks, for each element in the list, a new stack frame is created. Instead of the RunnableChain construct, a simple ArrayList can be used as queue which will be faster and use less memory.
1 parent 44d9ebe commit 2655fd6

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

org.eclipse.draw2d/src/org/eclipse/draw2d/DeferredUpdateManager.java

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2024 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -57,26 +57,9 @@ public void run() {
5757

5858
private boolean updating;
5959
private boolean validating;
60-
private RunnableChain afterUpdate;
60+
private List<Runnable> afterUpdate = new ArrayList<>();
6161
private int refreshRate = -1;
6262

63-
private static class RunnableChain {
64-
RunnableChain next;
65-
Runnable run;
66-
67-
RunnableChain(Runnable run, RunnableChain next) {
68-
this.run = run;
69-
this.next = next;
70-
}
71-
72-
void run() {
73-
if (next != null) {
74-
next.run();
75-
}
76-
run.run();
77-
}
78-
}
79-
8063
/**
8164
* Empty constructor.
8265
*/
@@ -195,11 +178,11 @@ public synchronized void performUpdate() {
195178
performValidation();
196179
updateQueued = false;
197180
repairDamage();
198-
if (afterUpdate != null) {
199-
RunnableChain chain = afterUpdate;
200-
afterUpdate = null;
201-
chain.run(); // chain may queue additional Runnable.
202-
if (afterUpdate != null) {
181+
if (!afterUpdate.isEmpty()) {
182+
List<Runnable> chain = afterUpdate;
183+
afterUpdate = new ArrayList<>();
184+
chain.forEach(Runnable::run); // chain may queue additional Runnable.
185+
if (!afterUpdate.isEmpty()) {
203186
queueWork();
204187
}
205188
}
@@ -330,7 +313,7 @@ protected void repairDamage() {
330313
*/
331314
@Override
332315
public synchronized void runWithUpdate(Runnable runnable) {
333-
afterUpdate = new RunnableChain(runnable, afterUpdate);
316+
afterUpdate.add(runnable);
334317
if (!updating) {
335318
queueWork();
336319
}

0 commit comments

Comments
 (0)