Skip to content

Commit f3dbf3c

Browse files
committed
Simplify OperationZip ItemObserver
LinkedList permits null values, no need for NULL_SENTINEL.
1 parent c2baf93 commit f3dbf3c

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,9 @@ private static final class ItemObserver<T> implements Observer<T>, Subscription
202202
/** Reader-writer lock. */
203203
protected final ReadWriteLock rwLock;
204204
/** The queue. */
205-
public final Queue<Object> queue = new LinkedList<Object>();
205+
public final Queue<T> queue = new LinkedList<T>();
206206
/** The list of the other observers. */
207207
public final List<ItemObserver<T>> all;
208-
/** The null sentinel value. */
209-
protected static final Object NULL_SENTINEL = new Object();
210208
/** The global cancel. */
211209
protected final Subscription cancel;
212210
/** The subscription to the source. */
@@ -252,7 +250,7 @@ public void onNext(T value) {
252250
if (done) {
253251
return;
254252
}
255-
queue.add(value != null ? value : NULL_SENTINEL);
253+
queue.add(value);
256254
} finally {
257255
rwLock.readLock().unlock();
258256
}
@@ -297,7 +295,6 @@ public void unsubscribe() {
297295
toSource.unsubscribe();
298296
}
299297

300-
@SuppressWarnings("unchecked")
301298
private void runCollector() {
302299
if (rwLock.writeLock().tryLock()) {
303300
boolean cu = false;
@@ -311,13 +308,10 @@ private void runCollector() {
311308
cu = true;
312309
return;
313310
}
314-
continue;
311+
} else {
312+
T value = io.queue.peek();
313+
values.add(value);
315314
}
316-
Object v = io.queue.peek();
317-
if (v == NULL_SENTINEL) {
318-
v = null;
319-
}
320-
values.add((T) v);
321315
}
322316
if (values.size() == all.size()) {
323317
for (ItemObserver<T> io : all) {

0 commit comments

Comments
 (0)