Skip to content

Commit 3ace4a6

Browse files
committed
Optimize for 'count == 0'
1 parent f370aaf commit 3ace4a6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

rxjava-core/src/main/java/rx/operators/OperationSkipLast.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ public void onError(Throwable e) {
8585

8686
@Override
8787
public void onNext(T value) {
88+
if (count == 0) {
89+
// If count == 0, we do not need to put value into deque
90+
// and remove it at once. We can emit the value
91+
// directly.
92+
try {
93+
observer.onNext(value);
94+
} catch (Throwable ex) {
95+
observer.onError(ex);
96+
subscription.unsubscribe();
97+
}
98+
return;
99+
}
88100
lock.lock();
89101
try {
90102
deque.offerLast(value);

0 commit comments

Comments
 (0)