Theoretical performance fix for #2062 "Massive search lag with external storage". Needs confirmation.

This commit is contained in:
raoulvdberge
2018-10-31 16:17:37 +01:00
parent bba5735604
commit 60a37bfe3d
4 changed files with 47 additions and 5 deletions

View File

@@ -34,7 +34,10 @@ public class GridFilterFilter implements Predicate<IGridStack> {
ItemStack stackInFilter = (ItemStack) filter.getStack();
if (filter.isModFilter()) {
if (stackInFilter.getItem().getRegistryName().getNamespace().equalsIgnoreCase(stack.getModId())) {
String stackModId = stack.getModId();
String filterModId = stackInFilter.getItem().getCreatorModId(stackInFilter);
if (filterModId != null && filterModId.equals(stackModId)) {
return filter.getMode() == IFilter.MODE_WHITELIST;
}
} else if (API.instance().getComparer().isEqual(((GridStackItem) stack).getStack(), stackInFilter, filter.getCompare())) {

View File

@@ -8,11 +8,32 @@ public class GridFilterMod implements Predicate<IGridStack> {
private String inputModName;
public GridFilterMod(String inputModName) {
this.inputModName = inputModName.toLowerCase().replace(" ", "");
this.inputModName = standardify(inputModName);
}
@Override
public boolean test(IGridStack stack) {
return stack.getModId().contains(inputModName) || stack.getModName().contains(inputModName);
String modId = stack.getModId();
if (modId != null) {
if (modId.contains(inputModName)) {
return true;
}
String modName = stack.getModName();
if (modName != null) {
modName = standardify(modName);
if (modName.contains(inputModName)) {
return true;
}
}
}
return false;
}
private String standardify(String input) {
return input.toLowerCase().replace(" ", "");
}
}

View File

@@ -4,6 +4,7 @@ import com.raoulvdberge.refinedstorage.api.storage.IStorageTracker;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.gui.GuiBase;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nullable;
@@ -58,7 +59,11 @@ public class GridStackFluid implements IGridStack {
@Override
public String getModId() {
if (modId == null) {
modId = stack.getFluid().getStill(stack).getNamespace();
modId = FluidRegistry.getModId(stack);
if (modId == null) {
modId = "???";
}
}
return modId;
@@ -68,6 +73,10 @@ public class GridStackFluid implements IGridStack {
public String getModName() {
if (modName == null) {
modName = GridStackItem.getModNameByModId(getModId());
if (modName == null) {
modName = "???";
}
}
return modName;

View File

@@ -45,13 +45,14 @@ public class GridStackItem implements IGridStack {
}
}
@Nullable
static String getModNameByModId(String modId) {
ModContainer container = Loader.instance().getActiveModList().stream()
.filter(m -> m.getModId().toLowerCase().equals(modId))
.findFirst()
.orElse(null);
return container == null ? modId : container.getName().toLowerCase().replace(" ", "");
return container == null ? null : container.getName();
}
public ItemStack getStack() {
@@ -99,6 +100,10 @@ public class GridStackItem implements IGridStack {
public String getModId() {
if (modId == null) {
modId = stack.getItem().getCreatorModId(stack);
if (modId == null) {
modId = "???";
}
}
return modId;
@@ -108,6 +113,10 @@ public class GridStackItem implements IGridStack {
public String getModName() {
if (modName == null) {
modName = getModNameByModId(getModId());
if (modName == null) {
modName = "???";
}
}
return modName;