From 5037adede907b1c03b0f4e8227d882f491f8481d Mon Sep 17 00:00:00 2001 From: malte0811 Date: Fri, 21 Aug 2020 06:29:02 +0200 Subject: [PATCH] Improve startup time by caching the manifest data for mod jars (#7256) --- .../fml/loading/moddiscovery/ModFileInfo.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/ModFileInfo.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/ModFileInfo.java index 8cb5d1c4e..ee92783e0 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/ModFileInfo.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/ModFileInfo.java @@ -54,6 +54,9 @@ public class ModFileInfo implements IModFileInfo, IConfigurable private final List mods; private final Map properties; private final String license; + // Caches the manifest of the mod jar as parsing the manifest can be expensive for + // signed jars. + private final Optional manifest; ModFileInfo(final ModFile modFile, final IConfigurable config) { @@ -72,7 +75,8 @@ public class ModFileInfo implements IModFileInfo, IConfigurable this.modFile.setFileProperties(this.properties); this.issueURL = config.getConfigElement("issueTrackerURL").map(StringUtils::toURL).orElse(null); final List modConfigs = config.getConfigList("mods"); - if (modConfigs.isEmpty()) { + if (modConfigs.isEmpty()) + { throw new InvalidModFileException("Missing mods list", this); } this.mods = modConfigs.stream() @@ -82,6 +86,7 @@ public class ModFileInfo implements IModFileInfo, IConfigurable this.modFile::getFileName, () -> this.mods.stream().map(IModInfo::getModId).collect(Collectors.joining(",", "{", "}")), () -> this.mods.stream().map(IModInfo::getVersion).map(Objects::toString).collect(Collectors.joining(",", "{", "}"))); + this.manifest = modFile.getLocator().findManifest(modFile.getFilePath()); } @Override @@ -108,31 +113,37 @@ public class ModFileInfo implements IModFileInfo, IConfigurable } @Override - public Map getFileProperties() { + public Map getFileProperties() + { return this.properties; } - public Optional getManifest() { - return modFile.getLocator().findManifest(modFile.getFilePath()); + public Optional getManifest() + { + return manifest; } @Override - public boolean showAsResourcePack() { + public boolean showAsResourcePack() + { return this.showAsResourcePack; } @Override - public Optional getConfigElement(final String... key) { + public Optional getConfigElement(final String... key) + { return this.config.getConfigElement(key); } @Override - public List getConfigList(final String... key) { + public List getConfigList(final String... key) + { return this.config.getConfigList(key); } @Override - public String getLicense() { + public String getLicense() + { return license; } }