Improve startup time by caching the manifest data for mod jars (#7256)

This commit is contained in:
malte0811 2020-08-21 06:29:02 +02:00 committed by GitHub
parent a5aca97e31
commit 5037adede9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -54,6 +54,9 @@ public class ModFileInfo implements IModFileInfo, IConfigurable
private final List<IModInfo> mods; private final List<IModInfo> mods;
private final Map<String,Object> properties; private final Map<String,Object> properties;
private final String license; 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> manifest;
ModFileInfo(final ModFile modFile, final IConfigurable config) ModFileInfo(final ModFile modFile, final IConfigurable config)
{ {
@ -72,7 +75,8 @@ public class ModFileInfo implements IModFileInfo, IConfigurable
this.modFile.setFileProperties(this.properties); this.modFile.setFileProperties(this.properties);
this.issueURL = config.<String>getConfigElement("issueTrackerURL").map(StringUtils::toURL).orElse(null); this.issueURL = config.<String>getConfigElement("issueTrackerURL").map(StringUtils::toURL).orElse(null);
final List<? extends IConfigurable> modConfigs = config.getConfigList("mods"); final List<? extends IConfigurable> modConfigs = config.getConfigList("mods");
if (modConfigs.isEmpty()) { if (modConfigs.isEmpty())
{
throw new InvalidModFileException("Missing mods list", this); throw new InvalidModFileException("Missing mods list", this);
} }
this.mods = modConfigs.stream() this.mods = modConfigs.stream()
@ -82,6 +86,7 @@ public class ModFileInfo implements IModFileInfo, IConfigurable
this.modFile::getFileName, this.modFile::getFileName,
() -> this.mods.stream().map(IModInfo::getModId).collect(Collectors.joining(",", "{", "}")), () -> this.mods.stream().map(IModInfo::getModId).collect(Collectors.joining(",", "{", "}")),
() -> this.mods.stream().map(IModInfo::getVersion).map(Objects::toString).collect(Collectors.joining(",", "{", "}"))); () -> this.mods.stream().map(IModInfo::getVersion).map(Objects::toString).collect(Collectors.joining(",", "{", "}")));
this.manifest = modFile.getLocator().findManifest(modFile.getFilePath());
} }
@Override @Override
@ -108,31 +113,37 @@ public class ModFileInfo implements IModFileInfo, IConfigurable
} }
@Override @Override
public Map<String, Object> getFileProperties() { public Map<String, Object> getFileProperties()
{
return this.properties; return this.properties;
} }
public Optional<Manifest> getManifest() { public Optional<Manifest> getManifest()
return modFile.getLocator().findManifest(modFile.getFilePath()); {
return manifest;
} }
@Override @Override
public boolean showAsResourcePack() { public boolean showAsResourcePack()
{
return this.showAsResourcePack; return this.showAsResourcePack;
} }
@Override @Override
public <T> Optional<T> getConfigElement(final String... key) { public <T> Optional<T> getConfigElement(final String... key)
{
return this.config.getConfigElement(key); return this.config.getConfigElement(key);
} }
@Override @Override
public List<? extends IConfigurable> getConfigList(final String... key) { public List<? extends IConfigurable> getConfigList(final String... key)
{
return this.config.getConfigList(key); return this.config.getConfigList(key);
} }
@Override @Override
public String getLicense() { public String getLicense()
{
return license; return license;
} }
} }