From c2acfb7d8a7f457e5d50c551ffc94f28f12a315b Mon Sep 17 00:00:00 2001 From: Balthild Date: Tue, 21 Apr 2020 21:06:17 +0800 Subject: [PATCH] Parallelize recipe handlers --- .../nei/recipe/GuiCraftingRecipe.java | 17 ++++++++--------- src/codechicken/nei/recipe/GuiUsageRecipe.java | 16 ++++++---------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/codechicken/nei/recipe/GuiCraftingRecipe.java b/src/codechicken/nei/recipe/GuiCraftingRecipe.java index b9c0e9cd..e4219123 100644 --- a/src/codechicken/nei/recipe/GuiCraftingRecipe.java +++ b/src/codechicken/nei/recipe/GuiCraftingRecipe.java @@ -6,6 +6,9 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiContainer; import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; public class GuiCraftingRecipe extends GuiRecipe { @@ -13,15 +16,11 @@ public class GuiCraftingRecipe extends GuiRecipe Minecraft mc = NEIClientUtils.mc(); GuiContainer prevscreen = mc.currentScreen instanceof GuiContainer ? (GuiContainer) mc.currentScreen : null; - TaskProfiler profiler = ProfilerRecipeHandler.getProfiler(); - ArrayList handlers = new ArrayList<>(); - for (ICraftingHandler craftinghandler : craftinghandlers) { - profiler.start(craftinghandler.getRecipeName()); - ICraftingHandler handler = craftinghandler.getRecipeHandler(outputId, results); - if (handler.numRecipes() > 0) - handlers.add(handler); - } - profiler.end(); + ArrayList handlers = craftinghandlers.parallelStream() + .map(h -> h.getRecipeHandler(outputId, results)) + .filter(h -> h.numRecipes() > 0) + .collect(Collectors.toCollection(ArrayList::new)); + if (handlers.isEmpty()) return false; diff --git a/src/codechicken/nei/recipe/GuiUsageRecipe.java b/src/codechicken/nei/recipe/GuiUsageRecipe.java index b479a6b2..c0a179b2 100644 --- a/src/codechicken/nei/recipe/GuiUsageRecipe.java +++ b/src/codechicken/nei/recipe/GuiUsageRecipe.java @@ -1,11 +1,11 @@ package codechicken.nei.recipe; -import codechicken.core.TaskProfiler; import codechicken.nei.NEIClientUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiContainer; import java.util.ArrayList; +import java.util.stream.Collectors; public class GuiUsageRecipe extends GuiRecipe { @@ -13,15 +13,11 @@ public class GuiUsageRecipe extends GuiRecipe Minecraft mc = NEIClientUtils.mc(); GuiContainer prevscreen = mc.currentScreen instanceof GuiContainer ? (GuiContainer) mc.currentScreen : null; - TaskProfiler profiler = ProfilerRecipeHandler.getProfiler(); - ArrayList handlers = new ArrayList<>(); - for (IUsageHandler usagehandler : usagehandlers) { - profiler.start(usagehandler.getRecipeName()); - IUsageHandler handler = usagehandler.getUsageHandler(inputId, ingredients); - if (handler.numRecipes() > 0) - handlers.add(handler); - } - profiler.end(); + ArrayList handlers = usagehandlers.parallelStream() + .map(h -> h.getUsageHandler(inputId, ingredients)) + .filter(h -> h.numRecipes() > 0) + .collect(Collectors.toCollection(ArrayList::new)); + if (handlers.isEmpty()) return false;