From 6f176ba86d139b13060e3c68d33ec70cd05359ce Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Sun, 16 Apr 2023 12:55:01 -0400 Subject: [PATCH 1/3] Remove reference to nonexistent config option --- .../embeddedt/modernfix/core/config/ModernFixEarlyConfig.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java b/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java index 83080de9..71449b20 100644 --- a/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java +++ b/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java @@ -81,7 +81,6 @@ public class ModernFixEarlyConfig { disableIfModPresent("mixin.perf.async_jei", "modernui"); disableIfModPresent("mixin.perf.compress_biome_container", "chocolate", "betterendforge"); disableIfModPresent("mixin.bugfix.mc218112", "performant"); - disableIfModPresent("mixin.perf.faster_baking", "touhou_little_maid"); disableIfModPresent("mixin.perf.reuse_datapacks", "tac"); } From 0f3c701d2acc1e73185eaf3b36b66210b0009671 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Sun, 16 Apr 2023 12:55:52 -0400 Subject: [PATCH 2/3] Prevent missing options from crashing the game --- .../modernfix/core/config/ModernFixEarlyConfig.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java b/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java index 71449b20..5af30d73 100644 --- a/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java +++ b/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java @@ -87,7 +87,11 @@ public class ModernFixEarlyConfig { private void disableIfModPresent(String configName, String... ids) { for(String id : ids) { if(FMLLoader.getLoadingModList().getModFileById(id) != null) { - this.options.get(configName).addModOverride(false, id); + Option option = this.options.get(configName); + if(option != null) + option.addModOverride(false, id); + else + LOGGER.warn("Can't disable missing option {}", configName); } } } From f8c5c50ce4ae4157c0bb472bd5385f7700a73ee4 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Sun, 16 Apr 2023 13:15:13 -0400 Subject: [PATCH 3/3] Improve speed of cache building --- .../ModFileResourcePackMixin.java | 8 +-- .../modernfix/util/CachedResourcePath.java | 60 +++++++++++++------ 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/embeddedt/modernfix/mixin/perf/resourcepacks/ModFileResourcePackMixin.java b/src/main/java/org/embeddedt/modernfix/mixin/perf/resourcepacks/ModFileResourcePackMixin.java index 84dcc9b7..a4af0a11 100644 --- a/src/main/java/org/embeddedt/modernfix/mixin/perf/resourcepacks/ModFileResourcePackMixin.java +++ b/src/main/java/org/embeddedt/modernfix/mixin/perf/resourcepacks/ModFileResourcePackMixin.java @@ -64,11 +64,11 @@ public abstract class ModFileResourcePackMixin { .map(path -> root.relativize(path.toAbsolutePath())) .filter(this::isValidCachedResourcePath) .forEach(path -> { - if(!path.toString().endsWith(".mcmeta")) { - rootListingPaths.add(new CachedResourcePath(path)); + CachedResourcePath listing = new CachedResourcePath(path); + if(!listing.getFileName().endsWith(".mcmeta")) { + rootListingPaths.add(listing); } - String mergedPath = slashJoiner.join(type.getDirectory(), namespace, path); - this.containedPaths.add(new CachedResourcePath(mergedPath)); + this.containedPaths.add(new CachedResourcePath(new String[] { type.getDirectory(), namespace }, listing)); }); rootListingPaths.trimToSize(); rootListingForNamespaces.put(namespace, rootListingPaths); diff --git a/src/main/java/org/embeddedt/modernfix/util/CachedResourcePath.java b/src/main/java/org/embeddedt/modernfix/util/CachedResourcePath.java index 9c210f17..4f3d287d 100644 --- a/src/main/java/org/embeddedt/modernfix/util/CachedResourcePath.java +++ b/src/main/java/org/embeddedt/modernfix/util/CachedResourcePath.java @@ -9,32 +9,58 @@ import com.google.common.collect.Streams; import java.lang.ref.WeakReference; import java.nio.file.Path; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; public class CachedResourcePath { - private final ImmutableList pathComponents; + private final String[] pathComponents; private int hashCode = 0; private static final Interner PATH_COMPONENT_INTERNER = Interners.newStrongInterner(); private static final Splitter SLASH_SPLITTER = Splitter.on('/'); private static final Joiner SLASH_JOINER = Joiner.on('/'); private WeakReference fullPathCache = new WeakReference<>(null); - - public CachedResourcePath(Iterable components) { - ImmutableList.Builder b = ImmutableList.builder(); - for(String s : components) { - if(s == null || s.length() == 0) - continue; - b.add(PATH_COMPONENT_INTERNER.intern(s)); - } - pathComponents = b.build(); - } + private static final String[] NO_PREFIX = new String[0]; public CachedResourcePath(Path path) { - this(() -> Streams.stream(path.iterator()).map(Path::toString).iterator()); + this(NO_PREFIX, path, path.getNameCount()); } public CachedResourcePath(String s) { - this(SLASH_SPLITTER.split(s)); + this(NO_PREFIX, SLASH_SPLITTER.splitToList(s)); + } + + public CachedResourcePath(String[] prefixElements, Collection collection) { + this(prefixElements, collection, collection.size()); + } + + public CachedResourcePath(String[] prefixElements, Iterable path, int count) { + String[] components = new String[prefixElements.length + count]; + int i = 0; + while(i < prefixElements.length) { + components[i] = PATH_COMPONENT_INTERNER.intern(prefixElements[i]); + i++; + } + for(Object component : path) { + String s = component.toString(); + if(s.length() == 0) + continue; + components[i] = PATH_COMPONENT_INTERNER.intern(s); + } + pathComponents = components; + } + + public CachedResourcePath(String[] prefixElements, CachedResourcePath other) { + String[] components = new String[prefixElements.length + other.pathComponents.length]; + int i = 0; + while(i < prefixElements.length) { + components[i] = PATH_COMPONENT_INTERNER.intern(prefixElements[i]); + i++; + } + System.arraycopy(other.pathComponents, 0, components, i, other.pathComponents.length); + pathComponents = components; } @Override @@ -42,7 +68,7 @@ public class CachedResourcePath { int result = hashCode; if(result != 0) return result; - hashCode = pathComponents.hashCode(); + hashCode = Arrays.hashCode(pathComponents); return hashCode; } @@ -51,15 +77,15 @@ public class CachedResourcePath { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; CachedResourcePath that = (CachedResourcePath) o; - return pathComponents.equals(that.pathComponents); + return Arrays.equals(pathComponents, that.pathComponents); } public String getFileName() { - return pathComponents.get(pathComponents.size() - 1); + return pathComponents[pathComponents.length - 1]; } public int getNameCount() { - return pathComponents.size(); + return pathComponents.length; } public String getFullPath() {