diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2021-11-16 13:32:24 +0000 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2021-11-16 13:32:24 +0000 |
commit | 670b3044c2f8d55af0b2f98f5578a78d7567a837 (patch) | |
tree | 52f12cae8766fec25adcfba7554dcdd578afe265 /src | |
parent | 4e2689d152f50a90e8c32c1229038d6e75e288ce (diff) | |
download | GT5-Unofficial-670b3044c2f8d55af0b2f98f5578a78d7567a837.tar.gz GT5-Unofficial-670b3044c2f8d55af0b2f98f5578a78d7567a837.tar.bz2 GT5-Unofficial-670b3044c2f8d55af0b2f98f5578a78d7567a837.zip |
Improved caching.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java b/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java index b423bfa91e..bf10b93ce8 100644 --- a/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java +++ b/src/main/java/gregtech/api/util/GT_AssemblyLineUtils.java @@ -19,9 +19,13 @@ import scala.actors.threadpool.Arrays; public class GT_AssemblyLineUtils { /** - * A cache of + * A cache of Recipes using the Output as Key. */ private static HashMap<GT_ItemStack, GT_Recipe_AssemblyLine> sRecipeCacheByOutput = new HashMap<GT_ItemStack, GT_Recipe_AssemblyLine>(); + /** + * A cache of Recipes using the Recipe Hash String as Key. + */ + private static HashMap<String, GT_Recipe_AssemblyLine> sRecipeCacheByRecipeHash = new HashMap<String, GT_Recipe_AssemblyLine>(); /** * Checks the DataStick for deprecated/invalid recipes, updating them as required. @@ -63,6 +67,14 @@ public class GT_AssemblyLineUtils { if (aTag == null) { return null; } + + //Get From Cache + if (doesDataStickHaveRecipeHash(aDataStick)) { + GT_Recipe_AssemblyLine aRecipeFromCache = sRecipeCacheByRecipeHash.get(getHashFromDataStack(aDataStick)); + if (aRecipeFromCache != null) { + return aRecipeFromCache; + } + } for (int i = 0; i < 15; i++) { int count = aTag.getInteger("a" + i); @@ -131,7 +143,11 @@ public class GT_AssemblyLineUtils { for (GT_Recipe_AssemblyLine aRecipe : GT_Recipe.GT_Recipe_AssemblyLine.sAssemblylineRecipes) { if (aRecipe.mEUt == aEU && aRecipe.mDuration == aTime) { if (GT_Utility.areStacksEqual(aOutputs[0], aRecipe.mOutput, true)) { - if (Arrays.equals(aRecipe.mInputs, aInputs) && Arrays.equals(aRecipe.mFluidInputs, aFluidInputs)) { + if (Arrays.equals(aRecipe.mInputs, aInputs) && Arrays.equals(aRecipe.mFluidInputs, aFluidInputs)) { + // Cache it + String aRecipeHash = generateRecipeHash(aRecipe); + sRecipeCacheByRecipeHash.put(aRecipeHash, aRecipe); + sRecipeCacheByOutput.put(new GT_ItemStack(aRecipe.mOutput), aRecipe); return aRecipe; } } @@ -165,6 +181,7 @@ public class GT_AssemblyLineUtils { if (GT_Utility.areStacksEqual(aRecipeOutput, aOutput)) { // Cache it to prevent future iterations of all recipes sRecipeCacheByOutput.put(aCacheStack, aRecipe); + sRecipeCacheByRecipeHash.put(generateRecipeHash(aRecipe), aRecipe); return aRecipe; } } |