Skip to content

Commit cbd09d7

Browse files
Merge pull request #1183 from akarnokd/NotificationLitePerf
NotificationLite.accept performance improvements
2 parents f00cba9 + 91d54a7 commit cbd09d7

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,22 @@ public Object error(Throwable e) {
111111
* @throws NullPointerException
112112
* if the {@link Observer} is null.
113113
*/
114+
@SuppressWarnings("unchecked")
114115
public void accept(Observer<? super T> o, Object n) {
115-
switch (kind(n)) {
116-
case OnNext:
117-
o.onNext(getValue(n));
118-
break;
119-
case OnCompleted:
116+
if (n == ON_COMPLETED_SENTINEL) {
120117
o.onCompleted();
121-
break;
122-
case OnError:
123-
o.onError(getError(n));
124-
break;
118+
} else
119+
if (n == ON_NEXT_NULL_SENTINEL) {
120+
o.onNext(null);
121+
} else
122+
if (n != null) {
123+
if (n.getClass() == OnErrorSentinel.class) {
124+
o.onError(((OnErrorSentinel)n).e);
125+
} else {
126+
o.onNext((T)n);
127+
}
128+
} else {
129+
throw new IllegalArgumentException("The lite notification can not be null");
125130
}
126131
}
127132

0 commit comments

Comments
 (0)