From 36aa78f405953c747ee86c0cddca3b5d18f5c755 Mon Sep 17 00:00:00 2001 From: zaaarf Date: Wed, 1 Mar 2023 22:22:14 +0100 Subject: chore: added targetclasses set to improve performance --- src/main/java/ftbsc/lll/loader/LilleroLoader.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/java/ftbsc/lll/loader/LilleroLoader.java b/src/main/java/ftbsc/lll/loader/LilleroLoader.java index 1a881df..0c0e90b 100644 --- a/src/main/java/ftbsc/lll/loader/LilleroLoader.java +++ b/src/main/java/ftbsc/lll/loader/LilleroLoader.java @@ -17,11 +17,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; -import java.util.Map; -import java.util.ServiceLoader; +import java.util.*; import java.util.stream.Collectors; public class LilleroLoader implements ILaunchPluginService { @@ -33,7 +29,8 @@ public class LilleroLoader implements ILaunchPluginService { public static final String NAME = "lll-loader"; - private List injectors = new ArrayList<>(); + private final Set injectors = new HashSet<>(); + private final Set targetClasses = new HashSet<>(); public LilleroLoader() { LOGGER.info(INIT, "Patch Loader initialized"); @@ -63,6 +60,7 @@ public class LilleroLoader implements ILaunchPluginService { for (IInjector inj : ServiceLoader.load(IInjector.class, loader)) { LOGGER.info(RESOURCE, "Registering injector {}", inj.name()); this.injectors.add(inj); + this.targetClasses.add(inj.targetClass()); } } catch (MalformedURLException e) { LOGGER.error(RESOURCE, "Malformed URL for resource {} - 'file:{}'", row.getKey(), row.getValue().toString()); @@ -84,13 +82,10 @@ public class LilleroLoader implements ILaunchPluginService { @Override public EnumSet handlesClass(Type classType, final boolean isEmpty, final String reason) { if (isEmpty) return NAY; - // TODO can I make a set of target classes to make this faster LOGGER.debug(HANDLER, "Inspecting class {}", classType.getClassName()); - for (IInjector inj : this.injectors) { - if (inj.targetClass().equals(classType.getClassName())) { - LOGGER.info(HANDLER, "Marked class {} as handled by {}", classType.getClassName(), LilleroLoader.NAME); - return YAY; - } + if(targetClasses.contains(classType.getClassName())) { + LOGGER.info(HANDLER, "Marked class {} as handled by {}", classType.getClassName(), LilleroLoader.NAME); + return YAY; } return NAY; } -- cgit v1.2.3-56-ga3b1