From f8c0de94f56807b8ccd0d0a27ced10b05a1f5f16 Mon Sep 17 00:00:00 2001 From: mezz Date: Sat, 26 Oct 2024 17:11:02 +0900 Subject: [PATCH] Improve performance of fetching all ingredients --- .../main/java/mezz/jei/gui/search/ElementSearch.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Gui/src/main/java/mezz/jei/gui/search/ElementSearch.java b/Gui/src/main/java/mezz/jei/gui/search/ElementSearch.java index 52d56f04c..0b6fb6340 100644 --- a/Gui/src/main/java/mezz/jei/gui/search/ElementSearch.java +++ b/Gui/src/main/java/mezz/jei/gui/search/ElementSearch.java @@ -22,6 +22,7 @@ public class ElementSearch implements IElementSearch { private final Map, IListElement>, PrefixedSearchable, IListElement>> prefixedSearchables = new IdentityHashMap<>(); private final CombinedSearchables> combinedSearchables = new CombinedSearchables<>(); + private final Set> allElements = Collections.newSetFromMap(new IdentityHashMap<>()); public ElementSearch(ElementPrefixParser elementPrefixParser) { for (PrefixInfo, IListElement> prefixInfo : elementPrefixParser.allPrefixInfos()) { @@ -57,6 +58,7 @@ public Set> getSearchResults(ElementPrefixParser.TokenInfo token @Override public void add(IListElementInfo info) { + this.allElements.add(info.getElement()); for (PrefixedSearchable, IListElement> prefixedSearchable : this.prefixedSearchables.values()) { SearchMode searchMode = prefixedSearchable.getMode(); if (searchMode != SearchMode.DISABLED) { @@ -71,6 +73,9 @@ public void add(IListElementInfo info) { @Override public void addAll(Collection> infos) { + for (IListElementInfo info : infos) { + this.allElements.add(info.getElement()); + } for (PrefixedSearchable, IListElement> prefixedSearchable : this.prefixedSearchables.values()) { SearchMode searchMode = prefixedSearchable.getMode(); if (searchMode != SearchMode.DISABLED) { @@ -87,10 +92,7 @@ public void addAll(Collection> infos) { @Override public Set> getAllIngredients() { - Set> results = Collections.newSetFromMap(new IdentityHashMap<>()); - PrefixedSearchable, IListElement> noPrefixSearchables = this.prefixedSearchables.get(ElementPrefixParser.NO_PREFIX); - noPrefixSearchables.getAllElements(results::addAll); - return results; + return Collections.unmodifiableSet(allElements); } @Override