Skip to content
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

Caching the result of 'isInternalImplementation' #447

Merged
merged 1 commit into from
Oct 22, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions rxjava-core/src/main/java/rx/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -128,6 +129,8 @@
*/
public class Observable<T> {

private final static ConcurrentHashMap<Class, Boolean> internalClassMap = new ConcurrentHashMap<Class, Boolean>();

/**
* Executed when 'subscribe' is invoked.
*/
Expand Down Expand Up @@ -4522,11 +4525,21 @@ private boolean isInternalImplementation(Object o) {
return true;
}
// prevent double-wrapping (yeah it happens)
if (o instanceof SafeObserver)
if (o instanceof SafeObserver) {
return true;
// we treat the following package as "internal" and don't wrap it
Package p = o.getClass().getPackage(); // it can be null
return p != null && p.getName().startsWith("rx.operators");
}

Class<?> clazz = o.getClass();
if (internalClassMap.containsKey(clazz)) {
//don't need to do reflection
return internalClassMap.get(clazz);
} else {
// we treat the following package as "internal" and don't wrap it
Package p = o.getClass().getPackage(); // it can be null
Boolean isInternal = (p != null && p.getName().startsWith("rx.operators"));
internalClassMap.put(clazz, isInternal);
return isInternal;
}
}

}