From f3dbf3c03919e39c2ce6a2e3d94216534a7bb5c8 Mon Sep 17 00:00:00 2001 From: Vadim Spivak Date: Wed, 22 Jan 2014 13:39:50 -0800 Subject: [PATCH] Simplify OperationZip ItemObserver LinkedList permits null values, no need for NULL_SENTINEL. --- .../src/main/java/rx/operators/OperationZip.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/rxjava-core/src/main/java/rx/operators/OperationZip.java b/rxjava-core/src/main/java/rx/operators/OperationZip.java index 9dd5637a6c..5b05946913 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationZip.java +++ b/rxjava-core/src/main/java/rx/operators/OperationZip.java @@ -202,11 +202,9 @@ private static final class ItemObserver implements Observer, Subscription /** Reader-writer lock. */ protected final ReadWriteLock rwLock; /** The queue. */ - public final Queue queue = new LinkedList(); + public final Queue queue = new LinkedList(); /** The list of the other observers. */ public final List> 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. */ @@ -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(); } @@ -297,7 +295,6 @@ public void unsubscribe() { toSource.unsubscribe(); } - @SuppressWarnings("unchecked") private void runCollector() { if (rwLock.writeLock().tryLock()) { boolean cu = false; @@ -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 io : all) {