Skip to content

Commit ca1b939

Browse files
committed
Cache native types to improve compile time.
Static.resolveConstruct() constituted over 16% of the total compile time on my test server. This reduces that to less than 1%.
1 parent 2bd9c67 commit ca1b939

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/main/java/com/laytonsmith/core/constructs/NativeTypeList.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,24 @@
1515
*/
1616
public class NativeTypeList {
1717

18+
private static Set<String> nativeTypes;
19+
1820
/**
1921
* Returns a list of all the known native classes.
2022
*
2123
* @return
2224
*/
2325
public static Set<String> getNativeTypeList() {
24-
Set<String> ret = new HashSet<>();
26+
if(nativeTypes != null) {
27+
return nativeTypes;
28+
}
29+
nativeTypes = new HashSet<>();
2530
for (ClassMirror<? extends Mixed> c : ClassDiscovery.getDefaultInstance().getClassesWithAnnotationThatExtend(typeof.class, Mixed.class)) {
26-
ret.add(c.loadAnnotation(typeof.class).value());
31+
nativeTypes.add(c.loadAnnotation(typeof.class).value());
2732
}
2833
// Also add this one in
29-
ret.add("mixed");
30-
return ret;
34+
nativeTypes.add("mixed");
35+
return nativeTypes;
3136
}
3237

3338
/**
@@ -70,7 +75,7 @@ public static Class<? extends Mixed> getNativeClassOrInterfaceRunner(String meth
7075
* @param methodscriptType
7176
* @return
7277
* @throws ClassNotFoundException If the methodscript type could not be found
73-
* @throws IllegalArgumentExceptio If the underlying type isn't a java interface or abstract class
78+
* @throws IllegalArgumentException If the underlying type isn't a java interface or abstract class
7479
*/
7580
public static Class<? extends MixedInterfaceRunner> getInterfaceRunnerFor(String methodscriptType) throws
7681
ClassNotFoundException, IllegalArgumentException {

0 commit comments

Comments
 (0)