Skip to content
Browse files

Add minor optimization to CClassType

If both compared classes are native, and one extends the other, we can
reliably say it is an instanceof, so just use the native java instanceof
mechanism. This only helps a tiny bit, but it does help, so this will
stay, even though this is not the correct solution.
  • Loading branch information...
LadyCailin committed Apr 5, 2019
1 parent 4fce2aa commit 92e71accccc63d32a49688e0f0c91e088c8ec6b8
Showing with 19 additions and 1 deletion.
  1. +19 −1 src/main/java/com/laytonsmith/core/constructs/
@@ -78,6 +78,13 @@
private Mixed[] invalidType = UNINITIALIZED;

* If this was constructed against a native class, we can do some optimizations in the course
* of operation. This may be null, and all code in this class must support the mechanisms if this
* is null anyways, but if it isn't null, then this can perhaps be used to help optimize.
private Class<? extends Mixed> nativeClass = null;

* This *MUST* contain a list of non type union types.
@@ -102,7 +109,9 @@ public static CClassType get(Class<? extends Mixed> type) {
throw new IllegalArgumentException("Missing typeof annotation for " + type);
String fqcn = typeof.value();
return get(FullyQualifiedClassName.forFullyQualifiedClass(fqcn));
CClassType t = get(FullyQualifiedClassName.forFullyQualifiedClass(fqcn));
t.nativeClass = type;
return t;
} catch (ClassNotFoundException ex) {
throw new Error(ex);
@@ -320,6 +329,15 @@ public static boolean doesExtend(CClassType checkClass, CClassType superClass) {
// more efficient check
return true;
if(checkClass.nativeClass != null && superClass.nativeClass != null
&& superClass.nativeClass.isAssignableFrom(checkClass.nativeClass)) {
// Since native classes are not allowed to extend multiple superclasees, but
// in general, they are allowed to advertise that they do, for the sake of
// methodscript, this can only be used to return true, if it returns true, it
// definitely is, but if it returns false, that does not explicitely mean that
// it doesn't.
return true;
for(CClassType tCheck : checkClass.getTypes()) {
for(CClassType tSuper : superClass.getTypes()) {
try {

0 comments on commit 92e71ac

Please sign in to comment.
You can’t perform that action at this time.