mirror of
https://github.com/GTNewHorizons/CodeChickenCore.git
synced 2026-11-26 15:12:56 +00:00
Speedup ClassDiscoverer by using ClassReader.SKIP_CODE (#33)
This commit is contained in:
1 parent
850e2b9368
commit
acd863e748
1 file changed
+6
-9
@@ -11,6 +11,7 @@ import java.util.zip.ZipFile;
|
|||||||
|
|
||||||
import net.minecraft.launchwrapper.Launch;
|
import net.minecraft.launchwrapper.Launch;
|
||||||
|
|
||||||
|
import org.objectweb.asm.ClassReader;
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
@@ -22,6 +23,7 @@ import cpw.mods.fml.common.Loader;
|
|||||||
import cpw.mods.fml.common.ModClassLoader;
|
import cpw.mods.fml.common.ModClassLoader;
|
||||||
import cpw.mods.fml.relauncher.CoreModManager;
|
import cpw.mods.fml.relauncher.CoreModManager;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class ClassDiscoverer {
|
public class ClassDiscoverer {
|
||||||
|
|
||||||
public IStringMatcher matcher;
|
public IStringMatcher matcher;
|
||||||
@@ -35,17 +37,12 @@ public class ClassDiscoverer {
|
|||||||
for (int i = 0; i < superclasses.length; i++)
|
for (int i = 0; i < superclasses.length; i++)
|
||||||
this.superclasses[i] = superclasses[i].getName().replace('.', '/');
|
this.superclasses[i] = superclasses[i].getName().replace('.', '/');
|
||||||
|
|
||||||
classes = new ArrayList<Class<?>>();
|
classes = new ArrayList<>();
|
||||||
modClassLoader = (ModClassLoader) Loader.instance().getModClassLoader();
|
modClassLoader = (ModClassLoader) Loader.instance().getModClassLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassDiscoverer(Class<?>... superclasses) {
|
public ClassDiscoverer(Class<?>... superclasses) {
|
||||||
this(new IStringMatcher() {
|
this(test -> true, superclasses);
|
||||||
|
|
||||||
public boolean matches(String test) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}, superclasses);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Class<?>> findClasses() {
|
public ArrayList<Class<?>> findClasses() {
|
||||||
@@ -63,7 +60,7 @@ public class ClassDiscoverer {
|
|||||||
byte[] bytes = Launch.classLoader.getClassBytes(classname);
|
byte[] bytes = Launch.classLoader.getClassBytes(classname);
|
||||||
if (bytes == null) return;
|
if (bytes == null) return;
|
||||||
|
|
||||||
ClassNode cnode = ASMHelper.createClassNode(bytes);
|
ClassNode cnode = ASMHelper.createClassNode(bytes, ClassReader.SKIP_CODE);
|
||||||
for (String superclass : superclasses)
|
for (String superclass : superclasses)
|
||||||
if (!cnode.interfaces.contains(superclass) && !cnode.superName.equals(superclass)) return;
|
if (!cnode.interfaces.contains(superclass) && !cnode.superName.equals(superclass)) return;
|
||||||
|
|
||||||
@@ -86,7 +83,7 @@ public class ClassDiscoverer {
|
|||||||
List<String> knownLibraries = ImmutableList.<String>builder().addAll(modClassLoader.getDefaultLibraries())
|
List<String> knownLibraries = ImmutableList.<String>builder().addAll(modClassLoader.getDefaultLibraries())
|
||||||
.addAll(CoreModManager.getLoadedCoremods()).build();
|
.addAll(CoreModManager.getLoadedCoremods()).build();
|
||||||
File[] minecraftSources = modClassLoader.getParentSources();
|
File[] minecraftSources = modClassLoader.getParentSources();
|
||||||
HashSet<String> searchedSources = new HashSet<String>();
|
HashSet<String> searchedSources = new HashSet<>();
|
||||||
for (File minecraftSource : minecraftSources) {
|
for (File minecraftSource : minecraftSources) {
|
||||||
if (searchedSources.contains(minecraftSource.getAbsolutePath())) continue;
|
if (searchedSources.contains(minecraftSource.getAbsolutePath())) continue;
|
||||||
searchedSources.add(minecraftSource.getAbsolutePath());
|
searchedSources.add(minecraftSource.getAbsolutePath());
|
||||||
|
|||||||
Reference in new issue
Block a user