From 9d3fc13f919e4bca2c337478f9719f169cd43c0d Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 26 Jul 2013 17:38:04 +0200 Subject: [PATCH] don't call "dispose" on each execution in case of compound callback --- .../intellij/openapi/util/ActionCallback.java | 10 ++++--- .../openapi/util/ExecutionCallback.java | 29 ++++++++++--------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/platform/core-api/src/com/intellij/openapi/util/ActionCallback.java b/platform/core-api/src/com/intellij/openapi/util/ActionCallback.java index bcfcaa92761e..334303bbf148 100644 --- a/platform/core-api/src/com/intellij/openapi/util/ActionCallback.java +++ b/platform/core-api/src/com/intellij/openapi/util/ActionCallback.java @@ -63,8 +63,9 @@ public class ActionCallback implements Disposable { } public void setDone() { - myDone.setExecuted(); - Disposer.dispose(this); + if (myDone.setExecuted()) { + Disposer.dispose(this); + } } public boolean isDone() { @@ -80,8 +81,9 @@ public class ActionCallback implements Disposable { } public void setRejected() { - myRejected.setExecuted(); - Disposer.dispose(this); + if (myRejected.setExecuted()) { + Disposer.dispose(this); + } } @NotNull diff --git a/platform/core-api/src/com/intellij/openapi/util/ExecutionCallback.java b/platform/core-api/src/com/intellij/openapi/util/ExecutionCallback.java index 54416b9510c4..3bf81fab9200 100644 --- a/platform/core-api/src/com/intellij/openapi/util/ExecutionCallback.java +++ b/platform/core-api/src/com/intellij/openapi/util/ExecutionCallback.java @@ -37,23 +37,26 @@ class ExecutionCallback { myCountToExecution = executedCount; } - void setExecuted() { + boolean setExecuted() { signalExecution(); - if (isExecuted()) { - Runnable[] all; - synchronized (this) { - if (myRunnables == null) { - all = ArrayUtil.EMPTY_RUNNABLE_ARRAY; - } - else { - all = myRunnables.toArray(new Runnable[myRunnables.size()]); - myRunnables.clear(); - } + if (!isExecuted()) { + return false; + } + + Runnable[] all; + synchronized (this) { + if (myRunnables == null) { + all = ArrayUtil.EMPTY_RUNNABLE_ARRAY; } - for (Runnable each : all) { - each.run(); + else { + all = myRunnables.toArray(new Runnable[myRunnables.size()]); + myRunnables.clear(); } } + for (Runnable each : all) { + each.run(); + } + return true; } private static class CompositeRunnable extends ArrayList implements Runnable {