Separate plugin types #10
|
@ -2,7 +2,6 @@ package dev.frogmc.frogloader.impl;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
import dev.frogmc.frogloader.api.FrogLoader;
|
import dev.frogmc.frogloader.api.FrogLoader;
|
||||||
import dev.frogmc.frogloader.api.mod.ModProperties;
|
import dev.frogmc.frogloader.api.mod.ModProperties;
|
||||||
|
@ -25,8 +24,8 @@ public class PluginLoader {
|
||||||
|
|
||||||
List<ModProvider> providers = new ArrayList<>(ServiceLoader.load(ModProvider.class).stream().map(ServiceLoader.Provider::get).toList()); // we need mutability & random access
|
List<ModProvider> providers = new ArrayList<>(ServiceLoader.load(ModProvider.class).stream().map(ServiceLoader.Provider::get).toList()); // we need mutability & random access
|
||||||
Map<String, Collection<ModProperties>> properties = new HashMap<>();
|
Map<String, Collection<ModProperties>> properties = new HashMap<>();
|
||||||
AtomicInteger size = new AtomicInteger(providers.size()); // use a separate size variable to not have to iterate over the list over and over again
|
int[] size = new int[providers.size()]; // use a separate size variable to not have to iterate over the list over and over again
|
||||||
for (int i = 0; i < size.get(); i++) {
|
for (int i = 0; i < size[0]; i++) {
|
||||||
Ecorous marked this conversation as resolved
Outdated
|
|||||||
ModProvider plugin = providers.get(i); // use random access to work around concurrent access (through modifications during iteration)
|
ModProvider plugin = providers.get(i); // use random access to work around concurrent access (through modifications during iteration)
|
||||||
LOGGER.debug("Found mod provider: {}", plugin.getClass().getName());
|
LOGGER.debug("Found mod provider: {}", plugin.getClass().getName());
|
||||||
if (!plugin.isApplicable()) {
|
if (!plugin.isApplicable()) {
|
||||||
|
@ -46,7 +45,7 @@ public class PluginLoader {
|
||||||
LOGGER.debug("Loaded {} mod(s) from provider: {}", loadedMods.size(), plugin.id());
|
LOGGER.debug("Loaded {} mod(s) from provider: {}", loadedMods.size(), plugin.id());
|
||||||
loadedMods.forEach(p -> p.extensions().runIfPresent(BuiltinExtensions.MOD_PROVIDER, ModProvider.class, provider -> {
|
loadedMods.forEach(p -> p.extensions().runIfPresent(BuiltinExtensions.MOD_PROVIDER, ModProvider.class, provider -> {
|
||||||
providers.add(provider);
|
providers.add(provider);
|
||||||
size.getAndIncrement();
|
size[0]++;
|
||||||
}));
|
}));
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
LOGGER.error("Error during plugin initialisation: ", e);
|
LOGGER.error("Error during plugin initialisation: ", e);
|
||||||
|
|
Loading…
Reference in a new issue
wouldn't
int[] size = new int[] { providers.size() }
be better as there's no need for thread safety?I believe this works better - but I wouldn't know as I didn't write it
The only difference here would be a insignificantly smaller memory footprint - this isn't an issue
It's not about performance, i think it's bad practice to use AtomicInteger when you don't need it
Resolved in
39ba054fcb