Skip to content

Commit

Permalink
Simplify OperationZip ItemObserver
Browse files Browse the repository at this point in the history
LinkedList permits null values, no need for NULL_SENTINEL.
  • Loading branch information
vadims committed Jan 22, 2014
1 parent c2baf93 commit f3dbf3c
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions rxjava-core/src/main/java/rx/operators/OperationZip.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,9 @@ private static final class ItemObserver<T> implements Observer<T>, Subscription
/** Reader-writer lock. */
protected final ReadWriteLock rwLock;
/** The queue. */
public final Queue<Object> queue = new LinkedList<Object>();
public final Queue<T> queue = new LinkedList<T>();
/** The list of the other observers. */
public final List<ItemObserver<T>> all;
/** The null sentinel value. */
protected static final Object NULL_SENTINEL = new Object();
/** The global cancel. */
protected final Subscription cancel;
/** The subscription to the source. */
Expand Down Expand Up @@ -252,7 +250,7 @@ public void onNext(T value) {
if (done) {
return;
}
queue.add(value != null ? value : NULL_SENTINEL);
queue.add(value);
} finally {
rwLock.readLock().unlock();
}
Expand Down Expand Up @@ -297,7 +295,6 @@ public void unsubscribe() {
toSource.unsubscribe();
}

@SuppressWarnings("unchecked")
private void runCollector() {
if (rwLock.writeLock().tryLock()) {
boolean cu = false;
Expand All @@ -311,13 +308,10 @@ private void runCollector() {
cu = true;
return;
}
continue;
} else {
T value = io.queue.peek();
values.add(value);
}
Object v = io.queue.peek();
if (v == NULL_SENTINEL) {
v = null;
}
values.add((T) v);
}
if (values.size() == all.size()) {
for (ItemObserver<T> io : all) {
Expand Down

0 comments on commit f3dbf3c

Please sign in to comment.