mirror of
https://github.com/GTNewHorizons/Applied-Energistics-2-Unofficial.git
synced 2026-10-26 14:25:20 +00:00
Trim arrays to size after mutations for memory savings (#277)
This commit is contained in:
1 parent
fc06a71212
commit
f6d9ae6d84
3 files changed
+14
-6
No files matched your search
@@ -76,7 +76,7 @@ public final class CraftingContext {
|
||||
/**
|
||||
* Ordered by priority
|
||||
*/
|
||||
public final Deque<CraftingTask> resolvers = new ArrayDeque<>(4);
|
||||
public final ArrayList<CraftingTask> resolvers = new ArrayList<>(4);
|
||||
|
||||
public RequestInProcessing(CraftingRequest<StackType> request) {
|
||||
this.request = request;
|
||||
@@ -127,6 +127,7 @@ public final class CraftingContext {
|
||||
}
|
||||
final RequestInProcessing<?> processing = new RequestInProcessing<>(request);
|
||||
processing.resolvers.addAll(CraftingCalculations.tryResolveCraftingRequest(request, this));
|
||||
Collections.reverse(processing.resolvers); // We remove from the end for efficient ArrayList usage
|
||||
liveRequests.add(processing);
|
||||
if (processing.resolvers.isEmpty()) {
|
||||
throw new IllegalStateException("No resolvers available for request " + request.toString());
|
||||
@@ -305,10 +306,13 @@ public final class CraftingContext {
|
||||
if (request.request.remainingToProcess <= 0 || request.resolvers.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
CraftingTask nextResolver = request.resolvers.removeFirst();
|
||||
CraftingTask nextResolver = request.resolvers.remove(request.resolvers.size() - 1);
|
||||
if (addResolverTask && !request.resolvers.isEmpty()) {
|
||||
tasksToProcess.addFirst(new CheckOtherResolversTask(request));
|
||||
}
|
||||
if (request.resolvers.isEmpty()) {
|
||||
request.resolvers.trimToSize();
|
||||
}
|
||||
tasksToProcess.addFirst(nextResolver);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -53,8 +53,8 @@ public class CraftableItemResolver implements CraftingRequestResolver<IAEItemSta
|
||||
// With the recursive part subtracted
|
||||
protected final IAEItemStack[] patternOutputs;
|
||||
protected final IAEItemStack matchingOutput;
|
||||
protected final List<RequestAndPerCraftAmount> childRequests = new ArrayList<>();
|
||||
protected final List<CraftingRequest> complexRequestPerSlot = new ArrayList<>();
|
||||
protected final ArrayList<RequestAndPerCraftAmount> childRequests = new ArrayList<>();
|
||||
protected final ArrayList<CraftingRequest> complexRequestPerSlot = new ArrayList<>();
|
||||
protected final Map<IAEItemStack, CraftingRequest<IAEItemStack>> childRecursionRequests = new HashMap<>();
|
||||
// byproduct injected -> amount per craft
|
||||
protected final IdentityHashMap<IAEItemStack, Long> byproducts = new IdentityHashMap<>();
|
||||
@@ -302,6 +302,8 @@ public class CraftableItemResolver implements CraftingRequestResolver<IAEItemSta
|
||||
childRequests.add(new RequestAndPerCraftAmount(req, input.getStackSize()));
|
||||
}
|
||||
}
|
||||
childRequests.trimToSize();
|
||||
complexRequestPerSlot.trimToSize();
|
||||
requestedInputs = true;
|
||||
state = State.NEEDS_MORE_WORK;
|
||||
return new StepOutput(Collections.unmodifiableList(newChildren));
|
||||
|
||||
@@ -18,8 +18,8 @@ public class ExtractItemResolver implements CraftingRequestResolver<IAEItemStack
|
||||
|
||||
public static class ExtractItemTask extends CraftingTask<IAEItemStack> {
|
||||
|
||||
public final List<IAEItemStack> removedFromSystem = new ArrayList<>();
|
||||
public final List<IAEItemStack> removedFromByproducts = new ArrayList<>();
|
||||
public final ArrayList<IAEItemStack> removedFromSystem = new ArrayList<>();
|
||||
public final ArrayList<IAEItemStack> removedFromByproducts = new ArrayList<>();
|
||||
|
||||
public ExtractItemTask(CraftingRequest<IAEItemStack> request) {
|
||||
super(request, CraftingTask.PRIORITY_EXTRACT); // always try to extract items first
|
||||
@@ -42,6 +42,8 @@ public class ExtractItemResolver implements CraftingRequestResolver<IAEItemStack
|
||||
extractFuzzy(context, context.itemModel, removedFromSystem);
|
||||
}
|
||||
}
|
||||
removedFromSystem.trimToSize();
|
||||
removedFromByproducts.trimToSize();
|
||||
return new StepOutput(Collections.emptyList());
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user