Skip to content

Commit f06aaeb

Browse files
JakeWhartonakarnokd
authored andcommitted
Re-use the single empty Disposable instance everywhere. (ReactiveX#4078)
1 parent 5f7b2e1 commit f06aaeb

2 files changed

Lines changed: 4 additions & 13 deletions

File tree

src/main/java/io/reactivex/disposables/Disposables.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
package io.reactivex.disposables;
1515

16+
import io.reactivex.internal.disposables.EmptyDisposable;
1617
import java.util.concurrent.*;
1718
import java.util.concurrent.atomic.AtomicReference;
1819

@@ -55,13 +56,8 @@ public void dispose() {
5556
};
5657
}
5758

58-
static final Disposable EMPTY = new Disposable() {
59-
@Override
60-
public void dispose() { }
61-
};
62-
6359
public static Disposable empty() {
64-
return EMPTY;
60+
return EmptyDisposable.INSTANCE;
6561
}
6662

6763
public static Disposable disposed() {

src/main/java/io/reactivex/internal/disposables/NbpFullArbiter.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,7 @@ public final class NbpFullArbiter<T> extends FullArbiterPad1 implements Disposab
3232
final SpscLinkedArrayQueue<Object> queue;
3333

3434
volatile Disposable s;
35-
static final Disposable INITIAL = new Disposable() {
36-
@Override
37-
public void dispose() { }
38-
};
39-
40-
35+
4136
Disposable resource;
4237

4338
volatile boolean cancelled;
@@ -46,7 +41,7 @@ public NbpFullArbiter(Observer<? super T> actual, Disposable resource, int capac
4641
this.actual = actual;
4742
this.resource = resource;
4843
this.queue = new SpscLinkedArrayQueue<Object>(capacity);
49-
this.s = INITIAL;
44+
this.s = EmptyDisposable.INSTANCE;
5045
}
5146

5247
@Override

0 commit comments

Comments
 (0)