aboutsummaryrefslogtreecommitdiff
path: root/RoughlyEnoughItems-runtime/src/main/java
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2020-09-07 22:08:32 +0800
committershedaniel <daniel@shedaniel.me>2020-09-07 22:08:32 +0800
commit5d94a3178457ec240030fc3162e7c2a6f4d41c6c (patch)
tree2df92ddfa1751e3088d798b0f8137989fa525cec /RoughlyEnoughItems-runtime/src/main/java
parent5533e1734362ab93248ebc6d0b67f2806cc5a53a (diff)
downloadRoughlyEnoughItems-5d94a3178457ec240030fc3162e7c2a6f4d41c6c.tar.gz
RoughlyEnoughItems-5d94a3178457ec240030fc3162e7c2a6f4d41c6c.tar.bz2
RoughlyEnoughItems-5d94a3178457ec240030fc3162e7c2a6f4d41c6c.zip
Improve memory usage
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'RoughlyEnoughItems-runtime/src/main/java')
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/AbstractEntryStack.java17
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java12
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java2
3 files changed, 20 insertions, 11 deletions
diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/AbstractEntryStack.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/AbstractEntryStack.java
index 53f1e79a6..91907294d 100644
--- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/AbstractEntryStack.java
+++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/AbstractEntryStack.java
@@ -23,7 +23,7 @@
package me.shedaniel.rei.impl;
-import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
+import it.unimi.dsi.fastutil.objects.Reference2ObjectMaps;
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
import me.shedaniel.rei.api.EntryStack;
import net.minecraft.client.gui.GuiComponent;
@@ -33,33 +33,38 @@ import java.util.Map;
@ApiStatus.Internal
public abstract class AbstractEntryStack extends GuiComponent implements EntryStack {
- private Reference2ObjectMap<Settings<?>, Object> settings = new Reference2ObjectOpenHashMap<>();
+ private static final Map<Settings<?>, Object> EMPTY_SETTINGS = Reference2ObjectMaps.emptyMap();
+ private Map<Settings<?>, Object> settings = null;
@Override
public <T> EntryStack setting(Settings<T> settings, T value) {
+ if (this.settings == null)
+ this.settings = new Reference2ObjectOpenHashMap<>(4);
this.settings.put(settings, value);
return this;
}
@Override
public <T> EntryStack removeSetting(Settings<T> settings) {
- this.settings.remove(settings);
+ if (this.settings != null && this.settings.remove(settings) != null && this.settings.isEmpty()) {
+ this.settings = null;
+ }
return this;
}
@Override
public EntryStack clearSettings() {
- this.settings.clear();
+ this.settings = null;
return this;
}
protected Map<Settings<?>, Object> getSettings() {
- return settings;
+ return this.settings == null ? EMPTY_SETTINGS : this.settings;
}
@Override
public <T> T get(Settings<T> settings) {
- Object o = this.settings.get(settings);
+ Object o = this.settings == null ? null : this.settings.get(settings);
if (o == null)
return settings.getDefaultValue();
return (T) o;
diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java
index 637acb134..a96f7ead8 100644
--- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java
+++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java
@@ -36,6 +36,7 @@ import me.shedaniel.rei.utils.CollectionUtils;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.core.NonNullList;
+import net.minecraft.core.Registry;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.ApiStatus;
@@ -53,7 +54,8 @@ public class EntryRegistryImpl implements EntryRegistry {
private final List<EntryStack> preFilteredList = Lists.newCopyOnWriteArrayList();
private final List<EntryStack> entries = Lists.newCopyOnWriteArrayList();
- private final List<AmountIgnoredEntryStackWrapper> reloadingRegistry = Lists.newArrayList();
+ @Nullable
+ private List<AmountIgnoredEntryStackWrapper> reloadingRegistry;
private boolean reloading;
private static EntryStack findFirstOrNullEqualsEntryIgnoreAmount(Collection<EntryStack> list, EntryStack obj) {
@@ -70,7 +72,7 @@ public class EntryRegistryImpl implements EntryRegistry {
reloadingRegistry.removeIf(AmountIgnoredEntryStackWrapper::isEmpty);
entries.clear();
entries.addAll(CollectionUtils.map(reloadingRegistry, AmountIgnoredEntryStackWrapper::unwrap));
- reloadingRegistry.clear();
+ reloadingRegistry = null;
}
@Override
@@ -121,9 +123,11 @@ public class EntryRegistryImpl implements EntryRegistry {
return (Predicate<T>) target.negate();
}
- public void reset() {
+ public void resetToReloadStart() {
entries.clear();
- reloadingRegistry.clear();
+ if (reloadingRegistry != null)
+ reloadingRegistry.clear();
+ reloadingRegistry = Lists.newArrayListWithCapacity(Registry.ITEM.keySet().size() + 100);
preFilteredList.clear();
reloading = true;
}
diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java
index 2e254962e..4d78312ed 100644
--- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java
+++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java
@@ -374,7 +374,7 @@ public class RecipeHelperImpl implements RecipeHelper {
plugins.sort(Comparator.comparingInt(REIPluginEntry::getPriority).reversed());
RoughlyEnoughItemsCore.LOGGER.info("Reloading REI, registered %d plugins: %s", plugins.size(), plugins.stream().map(REIPluginEntry::getPluginIdentifier).map(ResourceLocation::toString).collect(Collectors.joining(", ")));
Collections.reverse(plugins);
- entryRegistry.reset();
+ entryRegistry.resetToReloadStart();
List<REIPluginV0> reiPluginV0s = new ArrayList<>();
endSection(sectionData);
for (REIPluginEntry plugin : plugins) {