Skip to content

Commit b92391d

Browse files
Merge pull request #447 from mattrjacobs/internal-impl-cache
Caching the result of 'isInternalImplementation'
2 parents b5ec461 + f2db8b4 commit b92391d

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

rxjava-core/src/main/java/rx/Observable.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.Arrays;
2222
import java.util.Comparator;
2323
import java.util.List;
24+
import java.util.concurrent.ConcurrentHashMap;
2425
import java.util.concurrent.Future;
2526
import java.util.concurrent.TimeUnit;
2627

@@ -129,6 +130,8 @@
129130
*/
130131
public class Observable<T> {
131132

133+
private final static ConcurrentHashMap<Class, Boolean> internalClassMap = new ConcurrentHashMap<Class, Boolean>();
134+
132135
/**
133136
* Executed when 'subscribe' is invoked.
134137
*/
@@ -4545,11 +4548,21 @@ private boolean isInternalImplementation(Object o) {
45454548
return true;
45464549
}
45474550
// prevent double-wrapping (yeah it happens)
4548-
if (o instanceof SafeObserver)
4551+
if (o instanceof SafeObserver) {
45494552
return true;
4550-
// we treat the following package as "internal" and don't wrap it
4551-
Package p = o.getClass().getPackage(); // it can be null
4552-
return p != null && p.getName().startsWith("rx.operators");
4553+
}
4554+
4555+
Class<?> clazz = o.getClass();
4556+
if (internalClassMap.containsKey(clazz)) {
4557+
//don't need to do reflection
4558+
return internalClassMap.get(clazz);
4559+
} else {
4560+
// we treat the following package as "internal" and don't wrap it
4561+
Package p = o.getClass().getPackage(); // it can be null
4562+
Boolean isInternal = (p != null && p.getName().startsWith("rx.operators"));
4563+
internalClassMap.put(clazz, isInternal);
4564+
return isInternal;
4565+
}
45534566
}
45544567

45554568
}

0 commit comments

Comments
 (0)