Skip to content

Commit 62f4bb3

Browse files
committed
Remove redundant comments.
1 parent 9d38e5f commit 62f4bb3

2 files changed

Lines changed: 6 additions & 15 deletions

File tree

driver-core/src/main/com/mongodb/internal/async/AsyncTrampoline.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ public final class AsyncTrampoline {
4646

4747
private static final ThreadLocal<Bounce> TRAMPOLINE = new ThreadLocal<>();
4848

49-
private AsyncTrampoline() {
50-
}
49+
private AsyncTrampoline() {}
5150

5251
/**
5352
* Execute work through the trampoline. If no trampoline is active, become the owner
@@ -56,15 +55,12 @@ private AsyncTrampoline() {
5655
public static void run(final Runnable work) {
5756
Bounce bounce = TRAMPOLINE.get();
5857
if (bounce != null) {
59-
// Re-entrant, enqueue and return
6058
bounce.enqueue(work);
6159
} else {
62-
// Become the trampoline owner.
6360
bounce = new Bounce();
6461
TRAMPOLINE.set(bounce);
6562
try {
6663
work.run();
67-
// drain any re-entrant work iteratively
6864
while (bounce.work != null) {
6965
Runnable workToRun = bounce.work;
7066
bounce.work = null;
@@ -87,8 +83,7 @@ private static final class Bounce {
8783

8884
void enqueue(final Runnable task) {
8985
if (this.work != null) {
90-
throw new AssertionError("Trampoline slot already occupied. "
91-
+ "It could happen if there are multiple concurrent operations in a sequential async chain.");
86+
throw new AssertionError("Trampoline slot already occupied");
9287
}
9388
this.work = task;
9489
}

driver-core/src/main/com/mongodb/internal/async/function/AsyncCallbackLoop.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,15 @@ public void run(final SingleResultCallback<Void> callback) {
5959

6060
/**
6161
* This callback is allowed to be completed more than once.
62-
* Also implements {@linkplain Runnable} to avoid lambda allocation per iteration when using trampoline.
6362
*/
6463
@NotThreadSafe
65-
private class LoopingCallback implements SingleResultCallback<Void>, Runnable {
64+
private class LoopingCallback implements SingleResultCallback<Void> {
6665
private final SingleResultCallback<Void> wrapped;
66+
private final Runnable nextIteration;
6767

6868
LoopingCallback(final SingleResultCallback<Void> callback) {
6969
wrapped = callback;
70-
}
71-
72-
@Override
73-
public void run() {
74-
body.run(this);
70+
nextIteration = () -> body.run(this);
7571
}
7672

7773
@Override
@@ -87,7 +83,7 @@ public void onResult(@Nullable final Void result, @Nullable final Throwable t) {
8783
return;
8884
}
8985
if (continueLooping) {
90-
AsyncTrampoline.run(this);
86+
AsyncTrampoline.run(nextIteration);
9187
} else {
9288
wrapped.onResult(result, null);
9389
}

0 commit comments

Comments
 (0)