Better perf for merging

This commit is contained in:
Raoul Van den Berge
2016-05-20 14:00:44 +02:00
parent 90994bc5a4
commit b1aff2389d
2 changed files with 17 additions and 19 deletions

View File

@@ -73,7 +73,8 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
private List<WirelessGridConsumer> wirelessGridConsumers = new ArrayList<WirelessGridConsumer>(); private List<WirelessGridConsumer> wirelessGridConsumers = new ArrayList<WirelessGridConsumer>();
private List<WirelessGridConsumer> wirelessGridConsumersToRemove = new ArrayList<WirelessGridConsumer>(); private List<WirelessGridConsumer> wirelessGridConsumersToRemove = new ArrayList<WirelessGridConsumer>();
private List<Integer> combinedGroups = new ArrayList<Integer>(); private Set<Integer> combinedGroupsIndices = new HashSet<Integer>();
private List<ItemGroup> combinedGroups = new ArrayList<ItemGroup>();
private RedstoneMode redstoneMode = RedstoneMode.IGNORE; private RedstoneMode redstoneMode = RedstoneMode.IGNORE;
@@ -127,12 +128,10 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
} }
for (TileMachine machine : machines) { for (TileMachine machine : machines) {
if (!machine.mayUpdate()) { if (machine.mayUpdate()) {
continue;
}
machine.updateMachine(); machine.updateMachine();
} }
}
for (ICraftingTask taskToCancel : craftingTasksToCancel) { for (ICraftingTask taskToCancel : craftingTasksToCancel) {
taskToCancel.onCancelled(this); taskToCancel.onCancelled(this);
@@ -329,40 +328,39 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
} }
combinedGroups.clear(); combinedGroups.clear();
combinedGroupsIndices.clear();
for (int i = 0; i < itemGroups.size(); ++i) { for (int i = 0; i < itemGroups.size(); ++i) {
ItemGroup group = itemGroups.get(i); if (combinedGroupsIndices.contains(i)) {
if (combinedGroups.contains(i)) {
continue; continue;
} }
ItemGroup group = itemGroups.get(i);
// If the item doesn't exist anymore, remove it from storage to avoid crashes // If the item doesn't exist anymore, remove it from storage to avoid crashes
if (group.getType() == null) { if (group.getType() == null) {
combinedGroups.add(i); combinedGroups.add(group);
combinedGroupsIndices.add(i);
} else { } else {
for (int j = i + 1; j < itemGroups.size(); ++j) { for (int j = i + 1; j < itemGroups.size(); ++j) {
ItemGroup otherGroup = itemGroups.get(j); if (combinedGroupsIndices.contains(j)) {
if (combinedGroups.contains(j)) {
continue; continue;
} }
ItemGroup otherGroup = itemGroups.get(j);
if (group.compareNoQuantity(otherGroup)) { if (group.compareNoQuantity(otherGroup)) {
// We copy here so we don't modify the quantity of the item group IStorage uses // We copy here so we don't modify the quantity of the item group IStorage uses
itemGroups.set(i, group.copy(group.getQuantity() + otherGroup.getQuantity())); itemGroups.set(i, group.copy(group.getQuantity() + otherGroup.getQuantity()));
combinedGroups.add(j); combinedGroups.add(otherGroup);
combinedGroupsIndices.add(j);
} }
} }
} }
} }
Collections.sort(combinedGroups, Collections.reverseOrder()); itemGroups.removeAll(combinedGroups);
for (int i : combinedGroups) {
itemGroups.remove(i);
}
} }
public boolean push(ItemStack stack) { public boolean push(ItemStack stack) {

View File

@@ -60,7 +60,7 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
for (int i = 0; i < inventory.getSizeInventory(); ++i) { for (int i = 0; i < inventory.getSizeInventory(); ++i) {
if (inventory.getStackInSlot(i) != null) { if (inventory.getStackInSlot(i) != null) {
items.add(new ItemGroup(inventory.getStackInSlot(i))); items.add(new ItemGroup(inventory.getStackInSlot(i).copy()));
} }
} }
} }