-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2.x: Improve coverage, fix operator logic 03/12 #5910
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,24 +196,20 @@ void next() { | |
|
||
BufferBoundarySubscriber<T, U, B> bs = new BufferBoundarySubscriber<T, U, B>(this); | ||
|
||
Disposable o = other.get(); | ||
|
||
if (!other.compareAndSet(o, bs)) { | ||
return; | ||
} | ||
|
||
U b; | ||
synchronized (this) { | ||
b = buffer; | ||
if (b == null) { | ||
return; | ||
if (DisposableHelper.replace(other, bs)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use dedicated helper instead of a CAS, plus the old code could unset a terminal indicator. |
||
U b; | ||
synchronized (this) { | ||
b = buffer; | ||
if (b == null) { | ||
return; | ||
} | ||
buffer = next; | ||
} | ||
buffer = next; | ||
} | ||
|
||
boundary.subscribe(bs); | ||
boundary.subscribe(bs); | ||
|
||
fastPathEmitMax(b, false, this); | ||
fastPathEmitMax(b, false, this); | ||
} | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,8 +177,8 @@ public void request(long n) { | |
|
||
@Override | ||
public void cancel() { | ||
cancelled = true; | ||
s.cancel(); | ||
|
||
DisposableHelper.dispose(timer); | ||
} | ||
|
||
|
@@ -199,14 +199,10 @@ public void run() { | |
|
||
synchronized (this) { | ||
current = buffer; | ||
if (current != null) { | ||
buffer = next; | ||
if (current == null) { | ||
return; | ||
} | ||
} | ||
|
||
if (current == null) { | ||
DisposableHelper.dispose(timer); | ||
return; | ||
buffer = next; | ||
} | ||
|
||
fastPathEmitMax(current, false, this); | ||
|
@@ -324,9 +320,10 @@ public void request(long n) { | |
|
||
@Override | ||
public void cancel() { | ||
clear(); | ||
cancelled = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
s.cancel(); | ||
w.dispose(); | ||
clear(); | ||
} | ||
|
||
void clear() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,7 +58,7 @@ static final class DebounceTimedSubscriber<T> extends AtomicLong | |
|
||
Subscription s; | ||
|
||
final SequentialDisposable timer = new SequentialDisposable(); | ||
Disposable timer; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Timer is only manipulated from |
||
|
||
volatile long index; | ||
|
||
|
@@ -88,17 +88,15 @@ public void onNext(T t) { | |
long idx = index + 1; | ||
index = idx; | ||
|
||
Disposable d = timer.get(); | ||
Disposable d = timer; | ||
if (d != null) { | ||
d.dispose(); | ||
} | ||
|
||
DebounceEmitter<T> de = new DebounceEmitter<T>(t, idx, this); | ||
if (timer.replace(de)) { | ||
d = worker.schedule(de, timeout, unit); | ||
|
||
de.setResource(d); | ||
} | ||
timer = de; | ||
d = worker.schedule(de, timeout, unit); | ||
de.setResource(d); | ||
} | ||
|
||
@Override | ||
|
@@ -108,6 +106,10 @@ public void onError(Throwable t) { | |
return; | ||
} | ||
done = true; | ||
Disposable d = timer; | ||
if (d != null) { | ||
d.dispose(); | ||
} | ||
actual.onError(t); | ||
worker.dispose(); | ||
} | ||
|
@@ -119,17 +121,18 @@ public void onComplete() { | |
} | ||
done = true; | ||
|
||
Disposable d = timer.get(); | ||
if (!DisposableHelper.isDisposed(d)) { | ||
@SuppressWarnings("unchecked") | ||
DebounceEmitter<T> de = (DebounceEmitter<T>)d; | ||
if (de != null) { | ||
de.emit(); | ||
} | ||
DisposableHelper.dispose(timer); | ||
actual.onComplete(); | ||
worker.dispose(); | ||
Disposable d = timer; | ||
if (d != null) { | ||
d.dispose(); | ||
} | ||
@SuppressWarnings("unchecked") | ||
DebounceEmitter<T> de = (DebounceEmitter<T>)d; | ||
if (de != null) { | ||
de.emit(); | ||
} | ||
|
||
actual.onComplete(); | ||
worker.dispose(); | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,24 +190,20 @@ void next() { | |
|
||
BufferBoundaryObserver<T, U, B> bs = new BufferBoundaryObserver<T, U, B>(this); | ||
|
||
Disposable o = other.get(); | ||
|
||
if (!other.compareAndSet(o, bs)) { | ||
return; | ||
} | ||
|
||
U b; | ||
synchronized (this) { | ||
b = buffer; | ||
if (b == null) { | ||
return; | ||
if (DisposableHelper.replace(other, bs)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the helper method instead of a CAS that could replace a terminal indicator. |
||
U b; | ||
synchronized (this) { | ||
b = buffer; | ||
if (b == null) { | ||
return; | ||
} | ||
buffer = next; | ||
} | ||
buffer = next; | ||
} | ||
|
||
boundary.subscribe(bs); | ||
boundary.subscribe(bs); | ||
|
||
fastPathEmit(b, false, this); | ||
fastPathEmit(b, false, this); | ||
} | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ static final class DebounceTimedObserver<T> | |
|
||
Disposable s; | ||
|
||
final AtomicReference<Disposable> timer = new AtomicReference<Disposable>(); | ||
Disposable timer; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
volatile long index; | ||
|
||
|
@@ -80,18 +80,15 @@ public void onNext(T t) { | |
long idx = index + 1; | ||
index = idx; | ||
|
||
Disposable d = timer.get(); | ||
Disposable d = timer; | ||
if (d != null) { | ||
d.dispose(); | ||
} | ||
|
||
DebounceEmitter<T> de = new DebounceEmitter<T>(t, idx, this); | ||
if (timer.compareAndSet(d, de)) { | ||
d = worker.schedule(de, timeout, unit); | ||
|
||
de.setResource(d); | ||
} | ||
|
||
timer = de; | ||
d = worker.schedule(de, timeout, unit); | ||
de.setResource(d); | ||
} | ||
|
||
@Override | ||
|
@@ -100,6 +97,10 @@ public void onError(Throwable t) { | |
RxJavaPlugins.onError(t); | ||
return; | ||
} | ||
Disposable d = timer; | ||
if (d != null) { | ||
d.dispose(); | ||
} | ||
done = true; | ||
actual.onError(t); | ||
worker.dispose(); | ||
|
@@ -112,16 +113,17 @@ public void onComplete() { | |
} | ||
done = true; | ||
|
||
Disposable d = timer.get(); | ||
if (d != DisposableHelper.DISPOSED) { | ||
@SuppressWarnings("unchecked") | ||
DebounceEmitter<T> de = (DebounceEmitter<T>)d; | ||
if (de != null) { | ||
de.run(); | ||
} | ||
actual.onComplete(); | ||
worker.dispose(); | ||
Disposable d = timer; | ||
if (d != null) { | ||
d.dispose(); | ||
} | ||
@SuppressWarnings("unchecked") | ||
DebounceEmitter<T> de = (DebounceEmitter<T>)d; | ||
if (de != null) { | ||
de.run(); | ||
} | ||
actual.onComplete(); | ||
worker.dispose(); | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,12 +85,9 @@ public void onSubscribe(Disposable d) { | |
public void onSuccess(T value) { | ||
other.dispose(); | ||
|
||
Disposable a = get(); | ||
Disposable a = getAndSet(DisposableHelper.DISPOSED); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be called at most once anyway, so biasing towards the |
||
if (a != DisposableHelper.DISPOSED) { | ||
a = getAndSet(DisposableHelper.DISPOSED); | ||
if (a != DisposableHelper.DISPOSED) { | ||
actual.onSuccess(value); | ||
} | ||
actual.onSuccess(value); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,8 +58,7 @@ public List<T> apply(List<T> a, List<T> b) throws Exception { | |
while (at.hasNext()) { | ||
both.add(at.next()); | ||
} | ||
} else | ||
if (s2 != null) { | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At this point either |
||
both.add(s2); | ||
while (bt.hasNext()) { | ||
both.add(bt.next()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That
cause == root
case is borderline impossible, unless this method gets called withthis
.