aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2023-10-23 20:32:07 +0800
committershedaniel <daniel@shedaniel.me>2023-10-23 21:45:39 +0800
commit718fcccc62f180badfe3d9decec9a27068ce725c (patch)
tree7b65be9d8104baa83fee2ae0fb1cf9e86d93cb0c
parent7ca7269f61154d87ac6c152ee9c863c1f039b174 (diff)
downloadRoughlyEnoughItems-718fcccc62f180badfe3d9decec9a27068ce725c.tar.gz
RoughlyEnoughItems-718fcccc62f180badfe3d9decec9a27068ce725c.tar.bz2
RoughlyEnoughItems-718fcccc62f180badfe3d9decec9a27068ce725c.zip
Optimize collapsible group caching
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/search/AsyncSearchManager.java8
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java17
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/search/collapsed/CollapsedEntriesCache.java2
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryImpl.java12
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryList.java4
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListImpl.java23
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListener.java4
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/FilteredEntryList.java4
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/PreFilteredEntryList.java29
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/common/util/HNEntryStackWrapper.java55
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java4
11 files changed, 105 insertions, 57 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/AsyncSearchManager.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/AsyncSearchManager.java
index c1ab15fba..8d1f6f056 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/AsyncSearchManager.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/AsyncSearchManager.java
@@ -48,14 +48,14 @@ import java.util.function.UnaryOperator;
public class AsyncSearchManager {
private static final ExecutorService EXECUTOR_SERVICE = new ThreadCreator("REI-AsyncSearchManager").asService(Math.min(3, Runtime.getRuntime().availableProcessors()));
- private final Supplier<List<HashedEntryStackWrapper>> stacksProvider;
+ private final Supplier<List<? extends HashedEntryStackWrapper>> stacksProvider;
private final Supplier<Predicate<HashedEntryStackWrapper>> additionalPredicateSupplier;
private final UnaryOperator<HashedEntryStackWrapper> transformer;
private volatile Map.Entry<List<HashedEntryStackWrapper>, SearchFilter> last;
public volatile ExecutorTuple executor;
public volatile SearchFilter filter;
- public AsyncSearchManager(Supplier<List<HashedEntryStackWrapper>> stacksProvider, Supplier<Predicate<HashedEntryStackWrapper>> additionalPredicateSupplier, UnaryOperator<HashedEntryStackWrapper> transformer) {
+ public AsyncSearchManager(Supplier<List<? extends HashedEntryStackWrapper>> stacksProvider, Supplier<Predicate<HashedEntryStackWrapper>> additionalPredicateSupplier, UnaryOperator<HashedEntryStackWrapper> transformer) {
this.stacksProvider = stacksProvider;
this.additionalPredicateSupplier = additionalPredicateSupplier;
this.transformer = transformer;
@@ -134,7 +134,7 @@ public class AsyncSearchManager {
}
public static CompletableFuture<Map.Entry<List<HashedEntryStackWrapper>, SearchFilter>> get(SearchFilter filter, Predicate<HashedEntryStackWrapper> additionalPredicate,
- UnaryOperator<HashedEntryStackWrapper> transformer, List<HashedEntryStackWrapper> stacks, Map.Entry<List<HashedEntryStackWrapper>, SearchFilter> last,
+ UnaryOperator<HashedEntryStackWrapper> transformer, List<? extends HashedEntryStackWrapper> stacks, Map.Entry<List<HashedEntryStackWrapper>, SearchFilter> last,
AsyncSearchManager manager, Executor executor, Steps steps) {
int searchPartitionSize = ConfigObject.getInstance().getAsyncSearchPartitionSize();
boolean shouldAsync = ConfigObject.getInstance().shouldAsyncSearch() && stacks.size() > searchPartitionSize * 4;
@@ -144,7 +144,7 @@ public class AsyncSearchManager {
if (shouldAsync) {
List<CompletableFuture<List<HashedEntryStackWrapper>>> futures = Lists.newArrayList();
int partitions = 0;
- for (Iterable<HashedEntryStackWrapper> partitionStacks : CollectionUtils.partition(stacks, searchPartitionSize * 4)) {
+ for (Iterable<? extends HashedEntryStackWrapper> partitionStacks : CollectionUtils.partition(stacks, searchPartitionSize * 4)) {
final int finalPartitions = partitions;
futures.add(CompletableFuture.supplyAsync(() -> {
List<HashedEntryStackWrapper> filtered = Lists.newArrayList();
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java
index bd5034aa3..e0b7fd737 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java
@@ -24,7 +24,6 @@
package me.shedaniel.rei.impl.client.search.argument;
import com.google.common.base.MoreObjects;
-import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import it.unimi.dsi.fastutil.ints.IntList;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
@@ -33,12 +32,14 @@ import me.shedaniel.rei.api.client.registry.entry.EntryRegistry;
import me.shedaniel.rei.api.client.search.method.CharacterUnpackingInputMethod;
import me.shedaniel.rei.api.client.search.method.InputMethod;
import me.shedaniel.rei.api.common.entry.EntryStack;
+import me.shedaniel.rei.api.common.util.CollectionUtils;
import me.shedaniel.rei.impl.client.search.IntRange;
import me.shedaniel.rei.impl.client.search.argument.type.ArgumentType;
import me.shedaniel.rei.impl.client.search.argument.type.ArgumentTypesRegistry;
import me.shedaniel.rei.impl.client.search.collapsed.CollapsedEntriesCache;
import me.shedaniel.rei.impl.client.search.result.ArgumentApplicableResult;
import me.shedaniel.rei.impl.common.entry.type.EntryRegistryImpl;
+import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper;
import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@@ -78,18 +79,8 @@ public class Argument<T, R> {
public static void resetCache(boolean cache) {
Argument.cache = new ArgumentCache();
CollapsedEntriesCache.reset();
- Collection<HashedEntryStackWrapper> stacks = new AbstractCollection<>() {
- @Override
- public Iterator<HashedEntryStackWrapper> iterator() {
- return Iterators.transform(((EntryRegistryImpl) EntryRegistry.getInstance()).getComplexList().iterator(),
- HashedEntryStackWrapper::normalize);
- }
-
- @Override
- public int size() {
- return ((EntryRegistryImpl) EntryRegistry.getInstance()).getComplexList().size();
- }
- };
+ List<HashedEntryStackWrapper> stacks = CollectionUtils.map(((EntryRegistryImpl) EntryRegistry.getInstance()).getComplexList(),
+ HNEntryStackWrapper::normalize);
if (cache) {
Argument.cache.prepareFilter(stacks, ArgumentTypesRegistry.ARGUMENT_TYPE_LIST, ArgumentCache.EXECUTOR_SERVICE);
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/collapsed/CollapsedEntriesCache.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/collapsed/CollapsedEntriesCache.java
index fc7ada4e8..2f87b2295 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/collapsed/CollapsedEntriesCache.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/collapsed/CollapsedEntriesCache.java
@@ -51,7 +51,7 @@ public class CollapsedEntriesCache {
return instance;
}
- public void prepare(Collection<HashedEntryStackWrapper> stacks) {
+ public void prepare(Collection<? extends HashedEntryStackWrapper> stacks) {
Collection<CollapsibleEntryRegistryImpl.Entry> entries = ((CollapsibleEntryRegistryImpl) CollapsibleEntryRegistry.getInstance()).getEntries();
InternalLogger.getInstance().debug("Preparing collapsed entry groups cache with %d entries and %d stacks", entries.size(), stacks.size());
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryImpl.java
index 038786804..811f95f53 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryImpl.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryImpl.java
@@ -38,7 +38,7 @@ import me.shedaniel.rei.api.common.registry.ReloadStage;
import me.shedaniel.rei.api.common.util.CollectionUtils;
import me.shedaniel.rei.api.common.util.EntryStacks;
import me.shedaniel.rei.impl.common.InternalLogger;
-import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper;
+import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.core.NonNullList;
@@ -81,7 +81,7 @@ public class EntryRegistryImpl implements EntryRegistry {
@Override
public void startReload() {
this.listeners.clear();
- this.registryList.collectHashed().clear();
+ this.registryList.collectHN().clear();
this.entriesHash = new LongOpenHashSet();
this.filteredList = new PreFilteredEntryList(this, this.registryList);
this.listeners.add(filteredList);
@@ -121,17 +121,17 @@ public class EntryRegistryImpl implements EntryRegistry {
return Collections.unmodifiableList(filteredList.getList());
}
- public List<HashedEntryStackWrapper> getPreFilteredComplexList() {
+ public List<HNEntryStackWrapper> getPreFilteredComplexList() {
return Collections.unmodifiableList(filteredList.getComplexList());
}
- public List<HashedEntryStackWrapper> getComplexList() {
- return Collections.unmodifiableList(registryList.collectHashed());
+ public List<HNEntryStackWrapper> getComplexList() {
+ return Collections.unmodifiableList(registryList.collectHN());
}
@Override
public void refilter() {
- List<HashedEntryStackWrapper> stacks = registryList.collectHashed();
+ List<HNEntryStackWrapper> stacks = registryList.collectHN();
for (EntryRegistryListener listener : listeners) {
listener.onReFilter(stacks);
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryList.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryList.java
index 5b39024d8..101743097 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryList.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryList.java
@@ -25,7 +25,7 @@ package me.shedaniel.rei.impl.common.entry.type;
import it.unimi.dsi.fastutil.longs.LongList;
import me.shedaniel.rei.api.common.entry.EntryStack;
-import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper;
+import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper;
import java.util.List;
import java.util.stream.Stream;
@@ -37,7 +37,7 @@ public interface EntryRegistryList {
List<EntryStack<?>> collect();
- List<HashedEntryStackWrapper> collectHashed();
+ List<HNEntryStackWrapper> collectHN();
int indexOf(EntryStack<?> stack);
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListImpl.java
index 7d97bf179..1d0731a2d 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListImpl.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListImpl.java
@@ -25,6 +25,7 @@ package me.shedaniel.rei.impl.common.entry.type;
import it.unimi.dsi.fastutil.longs.LongList;
import me.shedaniel.rei.api.common.entry.EntryStack;
+import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper;
import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper;
import net.minecraft.core.Registry;
@@ -35,7 +36,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
public class EntryRegistryListImpl implements EntryRegistryList {
- private final List<HashedEntryStackWrapper> hashedList = new ArrayList<>(Registry.ITEM.keySet().size() + 100);
+ private final List<HNEntryStackWrapper> hashedList = new ArrayList<>(Registry.ITEM.keySet().size() + 100);
private final List<EntryStack<?>> list = createMappedList(hashedList);
public EntryRegistryListImpl() {
@@ -61,7 +62,7 @@ public class EntryRegistryListImpl implements EntryRegistryList {
}
@Override
- public List<HashedEntryStackWrapper> collectHashed() {
+ public List<HNEntryStackWrapper> collectHN() {
return hashedList;
}
@@ -77,20 +78,20 @@ public class EntryRegistryListImpl implements EntryRegistryList {
@Override
public void add(EntryStack<?> stack, long hashExact) {
- hashedList.add(new HashedEntryStackWrapper(stack, hashExact));
+ hashedList.add(new HNEntryStackWrapper(stack, hashExact));
}
@Override
public void add(int index, EntryStack<?> stack, long hashExact) {
- hashedList.add(index, new HashedEntryStackWrapper(stack, hashExact));
+ hashedList.add(index, new HNEntryStackWrapper(stack, hashExact));
}
@Override
public void addAll(List<EntryStack<?>> stacks, LongList hashes) {
hashedList.addAll(new AbstractList<>() {
@Override
- public HashedEntryStackWrapper get(int index) {
- return new HashedEntryStackWrapper(stacks.get(index), hashes.getLong(index));
+ public HNEntryStackWrapper get(int index) {
+ return new HNEntryStackWrapper(stacks.get(index), hashes.getLong(index));
}
@Override
@@ -104,8 +105,8 @@ public class EntryRegistryListImpl implements EntryRegistryList {
public void addAll(int index, List<EntryStack<?>> stacks, LongList hashes) {
hashedList.addAll(index, new AbstractList<>() {
@Override
- public HashedEntryStackWrapper get(int index) {
- return new HashedEntryStackWrapper(stacks.get(index), hashes.getLong(index));
+ public HNEntryStackWrapper get(int index) {
+ return new HNEntryStackWrapper(stacks.get(index), hashes.getLong(index));
}
@Override
@@ -134,7 +135,7 @@ public class EntryRegistryListImpl implements EntryRegistryList {
return list;
}
- private static List<EntryStack<?>> createMappedList(List<HashedEntryStackWrapper> hashedList) {
+ private static List<EntryStack<?>> createMappedList(List<HNEntryStackWrapper> hashedList) {
return new AbstractList<>() {
@Override
public EntryStack<?> get(int index) {
@@ -148,12 +149,12 @@ public class EntryRegistryListImpl implements EntryRegistryList {
@Override
public void add(int index, EntryStack<?> element) {
- hashedList.add(index, new HashedEntryStackWrapper(element));
+ hashedList.add(index, new HNEntryStackWrapper(element));
}
@Override
public EntryStack<?> set(int index, EntryStack<?> element) {
- return hashedList.set(index, new HashedEntryStackWrapper(element)).unwrap();
+ return hashedList.set(index, new HNEntryStackWrapper(element)).unwrap();
}
@Override
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListener.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListener.java
index df91ea28f..2d0f3d238 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListener.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListener.java
@@ -25,7 +25,7 @@ package me.shedaniel.rei.impl.common.entry.type;
import it.unimi.dsi.fastutil.longs.LongList;
import me.shedaniel.rei.api.common.entry.EntryStack;
-import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper;
+import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper;
import org.jetbrains.annotations.Nullable;
import java.util.List;
@@ -39,5 +39,5 @@ public interface EntryRegistryListener {
default void removeEntries(List<EntryStack<?>> stacks, @Nullable LongList hashes) {}
- default void onReFilter(List<HashedEntryStackWrapper> stacks) {}
+ default void onReFilter(List<HNEntryStackWrapper> stacks) {}
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/FilteredEntryList.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/FilteredEntryList.java
index 76393a51d..efe289659 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/FilteredEntryList.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/FilteredEntryList.java
@@ -26,7 +26,7 @@ package me.shedaniel.rei.impl.common.entry.type;
import it.unimi.dsi.fastutil.longs.LongCollection;
import me.shedaniel.rei.api.client.entry.filtering.FilteringRule;
import me.shedaniel.rei.api.common.entry.EntryStack;
-import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper;
+import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
@@ -40,7 +40,7 @@ public interface FilteredEntryList extends EntryRegistryListener {
List<EntryStack<?>> getList();
- List<HashedEntryStackWrapper> getComplexList();
+ List<HNEntryStackWrapper> getComplexList();
boolean isFiltered(EntryStack<?> stack, long hashExact);
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/PreFilteredEntryList.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/PreFilteredEntryList.java
index 03a4b47c3..3133afb20 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/PreFilteredEntryList.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/PreFilteredEntryList.java
@@ -39,6 +39,7 @@ import me.shedaniel.rei.api.common.util.CollectionUtils;
import me.shedaniel.rei.api.common.util.EntryStacks;
import me.shedaniel.rei.impl.client.entry.filtering.FilteringContextType;
import me.shedaniel.rei.impl.common.InternalLogger;
+import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper;
import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper;
import org.jetbrains.annotations.Nullable;
@@ -49,7 +50,7 @@ public class PreFilteredEntryList implements FilteredEntryList {
private final EntryRegistryList list;
private final Map<FilteringRule<?>, DataPair> filteringData = new HashMap<>();
private final Long2BooleanMap cached = new Long2BooleanOpenHashMap();
- private final List<HashedEntryStackWrapper> listView = new InternalListView();
+ private final List<HNEntryStackWrapper> listView = new InternalListView();
private final List<EntryStack<?>> simpleListView = new InternalSimpleListView(listView);
private long mod = 0;
@@ -87,7 +88,7 @@ public class PreFilteredEntryList implements FilteredEntryList {
}
@Override
- public void onReFilter(List<HashedEntryStackWrapper> stacks) {
+ public void onReFilter(List<HNEntryStackWrapper> stacks) {
ConfigObject config = ConfigObject.getInstance();
if (config.getFilteredStackProviders() != null) {
List<EntryStack<?>> normalizedFilteredStacks = CollectionUtils.map(config.getFilteredStackProviders(), EntryStackProvider::provide);
@@ -97,7 +98,7 @@ public class PreFilteredEntryList implements FilteredEntryList {
}
Stopwatch stopwatch = Stopwatch.createStarted();
- refreshFilteringFor(true, null, Lists.transform(stacks, HashedEntryStackWrapper::unwrap), new AbstractLongList() {
+ refreshFilteringFor(true, null, Lists.transform(stacks, HNEntryStackWrapper::unwrap), new AbstractLongList() {
@Override
public long getLong(int index) {
return stacks.get(index).hashExact();
@@ -216,16 +217,16 @@ public class PreFilteredEntryList implements FilteredEntryList {
}
@Override
- public List<HashedEntryStackWrapper> getComplexList() {
+ public List<HNEntryStackWrapper> getComplexList() {
return listView;
}
- private class InternalListView extends AbstractList<HashedEntryStackWrapper> {
+ private class InternalListView extends AbstractList<HNEntryStackWrapper> {
private long prevMod = -1;
- private List<HashedEntryStackWrapper> stacks;
+ private List<HNEntryStackWrapper> stacks;
@Override
- public HashedEntryStackWrapper get(int index) {
+ public HNEntryStackWrapper get(int index) {
if (prevMod == mod) {
return stacks.get(index);
}
@@ -250,18 +251,18 @@ public class PreFilteredEntryList implements FilteredEntryList {
}
@Override
- public Iterator<HashedEntryStackWrapper> iterator() {
+ public Iterator<HNEntryStackWrapper> iterator() {
if (prevMod == mod) {
return stacks.iterator();
}
- Iterator<HashedEntryStackWrapper> iterator = list.collectHashed().iterator();
+ Iterator<HNEntryStackWrapper> iterator = list.collectHN().iterator();
return new AbstractIterator<>() {
@Nullable
@Override
- protected HashedEntryStackWrapper computeNext() {
+ protected HNEntryStackWrapper computeNext() {
while (iterator.hasNext()) {
- HashedEntryStackWrapper wrapper = iterator.next();
+ HNEntryStackWrapper wrapper = iterator.next();
if (isFiltered(wrapper.unwrap(), wrapper.hashExact())) return wrapper;
}
@@ -272,9 +273,9 @@ public class PreFilteredEntryList implements FilteredEntryList {
}
private static class InternalSimpleListView extends AbstractList<EntryStack<?>> {
- private final List<HashedEntryStackWrapper> list;
+ private final List<HNEntryStackWrapper> list;
- public InternalSimpleListView(List<HashedEntryStackWrapper> list) {
+ public InternalSimpleListView(List<HNEntryStackWrapper> list) {
this.list = list;
}
@@ -290,7 +291,7 @@ public class PreFilteredEntryList implements FilteredEntryList {
@Override
public Iterator<EntryStack<?>> iterator() {
- return Iterators.transform(list.iterator(), HashedEntryStackWrapper::unwrap);
+ return Iterators.transform(list.iterator(), HNEntryStackWrapper::unwrap);
}
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/util/HNEntryStackWrapper.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/util/HNEntryStackWrapper.java
new file mode 100644
index 000000000..b442ff8c4
--- /dev/null
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/util/HNEntryStackWrapper.java
@@ -0,0 +1,55 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 shedaniel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package me.shedaniel.rei.impl.common.util;
+
+import me.shedaniel.rei.api.common.entry.EntryStack;
+import me.shedaniel.rei.api.common.util.EntryStacks;
+import org.jetbrains.annotations.ApiStatus;
+
+@ApiStatus.Internal
+public class HNEntryStackWrapper extends HashedEntryStackWrapper {
+ private final EntryStack<?> normalized;
+ private final long normalizedHash;
+
+ public HNEntryStackWrapper(EntryStack<?> stack) {
+ super(stack);
+ this.normalized = stack.normalize();
+ this.normalizedHash = EntryStacks.hashExact(this.normalized);
+ }
+
+ public HNEntryStackWrapper(EntryStack<?> stack, long hash) {
+ super(stack, hash);
+ this.normalized = stack.normalize();
+ this.normalizedHash = EntryStacks.hashExact(this.normalized);
+ }
+
+ public EntryStack<?> normalized() {
+ return normalized;
+ }
+
+ @Override
+ public HashedEntryStackWrapper normalize() {
+ return new HashedEntryStackWrapper(normalized, normalizedHash);
+ }
+} \ No newline at end of file
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java
index 339f0d7b0..ee5dc388c 100644
--- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java
@@ -64,7 +64,7 @@ import me.shedaniel.rei.impl.client.search.method.DefaultInputMethod;
import me.shedaniel.rei.impl.client.search.method.unihan.*;
import me.shedaniel.rei.impl.common.entry.type.EntryRegistryImpl;
import me.shedaniel.rei.impl.common.entry.type.EntryRegistryListener;
-import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper;
+import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper;
import me.shedaniel.rei.plugin.autocrafting.DefaultCategoryHandler;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@@ -119,7 +119,7 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin {
((EntryRegistryImpl) registry).listeners.add(new EntryRegistryListener() {
@Override
- public void onReFilter(List<HashedEntryStackWrapper> stacks) {
+ public void onReFilter(List<HNEntryStackWrapper> stacks) {
filteredStacksVisibilityHandler.reset();
}
});