mirror of
https://github.com/zaaarf/lillero-loader.git
synced 2024-11-21 20:44:48 +01:00
chore: added targetclasses set to improve performance
This commit is contained in:
parent
dd3a992463
commit
36aa78f405
1 changed files with 7 additions and 12 deletions
|
@ -17,11 +17,7 @@ import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.ServiceLoader;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class LilleroLoader implements ILaunchPluginService {
|
public class LilleroLoader implements ILaunchPluginService {
|
||||||
|
@ -33,7 +29,8 @@ public class LilleroLoader implements ILaunchPluginService {
|
||||||
|
|
||||||
public static final String NAME = "lll-loader";
|
public static final String NAME = "lll-loader";
|
||||||
|
|
||||||
private List<IInjector> injectors = new ArrayList<>();
|
private final Set<IInjector> injectors = new HashSet<>();
|
||||||
|
private final Set<String> targetClasses = new HashSet<>();
|
||||||
|
|
||||||
public LilleroLoader() {
|
public LilleroLoader() {
|
||||||
LOGGER.info(INIT, "Patch Loader initialized");
|
LOGGER.info(INIT, "Patch Loader initialized");
|
||||||
|
@ -63,6 +60,7 @@ public class LilleroLoader implements ILaunchPluginService {
|
||||||
for (IInjector inj : ServiceLoader.load(IInjector.class, loader)) {
|
for (IInjector inj : ServiceLoader.load(IInjector.class, loader)) {
|
||||||
LOGGER.info(RESOURCE, "Registering injector {}", inj.name());
|
LOGGER.info(RESOURCE, "Registering injector {}", inj.name());
|
||||||
this.injectors.add(inj);
|
this.injectors.add(inj);
|
||||||
|
this.targetClasses.add(inj.targetClass());
|
||||||
}
|
}
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
LOGGER.error(RESOURCE, "Malformed URL for resource {} - 'file:{}'", row.getKey(), row.getValue().toString());
|
LOGGER.error(RESOURCE, "Malformed URL for resource {} - 'file:{}'", row.getKey(), row.getValue().toString());
|
||||||
|
@ -84,13 +82,10 @@ public class LilleroLoader implements ILaunchPluginService {
|
||||||
@Override
|
@Override
|
||||||
public EnumSet<Phase> handlesClass(Type classType, final boolean isEmpty, final String reason) {
|
public EnumSet<Phase> handlesClass(Type classType, final boolean isEmpty, final String reason) {
|
||||||
if (isEmpty) return NAY;
|
if (isEmpty) return NAY;
|
||||||
// TODO can I make a set of target classes to make this faster
|
|
||||||
LOGGER.debug(HANDLER, "Inspecting class {}", classType.getClassName());
|
LOGGER.debug(HANDLER, "Inspecting class {}", classType.getClassName());
|
||||||
for (IInjector inj : this.injectors) {
|
if(targetClasses.contains(classType.getClassName())) {
|
||||||
if (inj.targetClass().equals(classType.getClassName())) {
|
LOGGER.info(HANDLER, "Marked class {} as handled by {}", classType.getClassName(), LilleroLoader.NAME);
|
||||||
LOGGER.info(HANDLER, "Marked class {} as handled by {}", classType.getClassName(), LilleroLoader.NAME);
|
return YAY;
|
||||||
return YAY;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return NAY;
|
return NAY;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue