Skip to content

Commit

Permalink
Improve performance of fetching all ingredients
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Oct 26, 2024
1 parent 21d1093 commit f8c0de9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Gui/src/main/java/mezz/jei/gui/search/ElementSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class ElementSearch implements IElementSearch {

private final Map<PrefixInfo<IListElementInfo<?>, IListElement<?>>, PrefixedSearchable<IListElementInfo<?>, IListElement<?>>> prefixedSearchables = new IdentityHashMap<>();
private final CombinedSearchables<IListElement<?>> combinedSearchables = new CombinedSearchables<>();
private final Set<IListElement<?>> allElements = Collections.newSetFromMap(new IdentityHashMap<>());

public ElementSearch(ElementPrefixParser elementPrefixParser) {
for (PrefixInfo<IListElementInfo<?>, IListElement<?>> prefixInfo : elementPrefixParser.allPrefixInfos()) {
Expand Down Expand Up @@ -57,6 +58,7 @@ public Set<IListElement<?>> getSearchResults(ElementPrefixParser.TokenInfo token

@Override
public void add(IListElementInfo<?> info) {
this.allElements.add(info.getElement());
for (PrefixedSearchable<IListElementInfo<?>, IListElement<?>> prefixedSearchable : this.prefixedSearchables.values()) {
SearchMode searchMode = prefixedSearchable.getMode();
if (searchMode != SearchMode.DISABLED) {
Expand All @@ -71,6 +73,9 @@ public void add(IListElementInfo<?> info) {

@Override
public void addAll(Collection<IListElementInfo<?>> infos) {
for (IListElementInfo<?> info : infos) {
this.allElements.add(info.getElement());
}
for (PrefixedSearchable<IListElementInfo<?>, IListElement<?>> prefixedSearchable : this.prefixedSearchables.values()) {
SearchMode searchMode = prefixedSearchable.getMode();
if (searchMode != SearchMode.DISABLED) {
Expand All @@ -87,10 +92,7 @@ public void addAll(Collection<IListElementInfo<?>> infos) {

@Override
public Set<IListElement<?>> getAllIngredients() {
Set<IListElement<?>> results = Collections.newSetFromMap(new IdentityHashMap<>());
PrefixedSearchable<IListElementInfo<?>, IListElement<?>> noPrefixSearchables = this.prefixedSearchables.get(ElementPrefixParser.NO_PREFIX);
noPrefixSearchables.getAllElements(results::addAll);
return results;
return Collections.unmodifiableSet(allElements);
}

@Override
Expand Down

0 comments on commit f8c0de9

Please sign in to comment.