From 9606ae46ff331148f54b92992642c1a374f26310 Mon Sep 17 00:00:00 2001 From: Zac Sweers Date: Fri, 17 Nov 2017 22:47:04 -0800 Subject: [PATCH] Inline lazyDispose() impl --- .../AutoDisposingSubscriberImpl.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/autodispose/src/main/java/com/uber/autodispose/AutoDisposingSubscriberImpl.java b/autodispose/src/main/java/com/uber/autodispose/AutoDisposingSubscriberImpl.java index 9918543ba..45192db9d 100755 --- a/autodispose/src/main/java/com/uber/autodispose/AutoDisposingSubscriberImpl.java +++ b/autodispose/src/main/java/com/uber/autodispose/AutoDisposingSubscriberImpl.java @@ -26,7 +26,8 @@ import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; -final class AutoDisposingSubscriberImpl extends AtomicInteger implements AutoDisposingSubscriber { +final class AutoDisposingSubscriberImpl extends AtomicInteger + implements AutoDisposingSubscriber { private final AtomicReference mainSubscription = new AtomicReference<>(); private final AtomicReference lifecycleDisposable = new AtomicReference<>(); @@ -100,11 +101,6 @@ final class AutoDisposingSubscriberImpl extends AtomicInteger implements Auto AutoSubscriptionHelper.cancel(mainSubscription); } - private void lazyCancel() { - AutoDisposableHelper.dispose(lifecycleDisposable); - mainSubscription.lazySet(AutoSubscriptionHelper.CANCELLED); - } - @SuppressWarnings("WeakerAccess") // Avoiding synthetic accessors void callMainSubscribeIfNecessary(Subscription s) { // If we've never actually started the upstream subscription (i.e. requested immediately in @@ -127,21 +123,24 @@ void callMainSubscribeIfNecessary(Subscription s) { if (!isDisposed()) { if (HalfSerializer.onNext(delegate, value, this, error)) { // Terminal event occurred and was forwarded to the delegate, so clean up here - lazyCancel(); + AutoDisposableHelper.dispose(lifecycleDisposable); + mainSubscription.lazySet(AutoSubscriptionHelper.CANCELLED); } } } @Override public void onError(Throwable e) { if (!isDisposed()) { - lazyCancel(); + AutoDisposableHelper.dispose(lifecycleDisposable); + mainSubscription.lazySet(AutoSubscriptionHelper.CANCELLED); HalfSerializer.onError(delegate, e, this, error); } } @Override public void onComplete() { if (!isDisposed()) { - lazyCancel(); + AutoDisposableHelper.dispose(lifecycleDisposable); + mainSubscription.lazySet(AutoSubscriptionHelper.CANCELLED); HalfSerializer.onComplete(delegate, this, error); } }