mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 19:41:59 -08:00
small performance update for ClassScanner
This commit is contained in:
parent
ed69c04490
commit
25e7b53268
1 changed files with 5 additions and 5 deletions
|
|
@ -33,8 +33,8 @@ public final class ClassScanner {
|
||||||
if(classLoader == null) classLoader = Thread.currentThread().getContextClassLoader();
|
if(classLoader == null) classLoader = Thread.currentThread().getContextClassLoader();
|
||||||
assert classLoader != null;
|
assert classLoader != null;
|
||||||
|
|
||||||
HashMap<String, String> dirs = new HashMap<>();
|
Map<String, String> dirs = new HashMap<>();
|
||||||
TreeSet<String> jars = new TreeSet<>();
|
Set<String> jars = new TreeSet<>();
|
||||||
for (String packageName : packages) {
|
for (String packageName : packages) {
|
||||||
String path = packageName.replace('.', '/');
|
String path = packageName.replace('.', '/');
|
||||||
Enumeration<URL> resources = classLoader.getResources(path);
|
Enumeration<URL> resources = classLoader.getResources(path);
|
||||||
|
|
@ -51,8 +51,8 @@ public final class ClassScanner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String filePath : dirs.keySet()) {
|
for (Map.Entry<String, String> dir : dirs.entrySet()) {
|
||||||
cards.addAll(findClasses(classLoader, new File(filePath), dirs.get(filePath), type));
|
cards.addAll(findClasses(classLoader, new File(dir.getKey()), dir.getValue(), type));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String filePath : jars) {
|
for (String filePath : jars) {
|
||||||
|
|
@ -66,7 +66,7 @@ public final class ClassScanner {
|
||||||
|
|
||||||
private static List<Class> findClasses(ClassLoader classLoader, File directory, String packageName, Class<?> type) {
|
private static List<Class> findClasses(ClassLoader classLoader, File directory, String packageName, Class<?> type) {
|
||||||
List<Class> cards = new ArrayList<>();
|
List<Class> cards = new ArrayList<>();
|
||||||
if (!directory.exists()) return cards;
|
if (directory == null || !directory.exists()) return cards;
|
||||||
|
|
||||||
for (File file : directory.listFiles()) {
|
for (File file : directory.listFiles()) {
|
||||||
if (file.getName().endsWith(".class")) {
|
if (file.getName().endsWith(".class")) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue