* Performance: memory usage optimization for deck editor (removed bloated usage of ManaCosts -> ManaColor objects, see #7515);

This commit is contained in:
Oleg Agafonov 2021-02-12 14:08:17 +04:00
parent c3d55ea12a
commit 275e996c08
23 changed files with 170 additions and 143 deletions

View file

@ -1398,11 +1398,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
}
// Casting cost
if (!s) {
String mc = "";
for (String m : card.getManaCost()) {
mc += m;
}
s |= mc.toLowerCase(Locale.ENGLISH).contains(searchStr);
s |= card.getManaCostStr().toLowerCase(Locale.ENGLISH).contains(searchStr);
}
// Rules
if (!s) {
@ -1473,10 +1469,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
}
// Mana Cost
String mc = "";
for (String m : card.getManaCost()) {
mc += m;
}
String mc = card.getManaCostStr();
mc = mc.replaceAll("\\{([WUBRG]).([WUBRG])\\}", "{$1}{$2}");
mc = mc.replaceAll("\\{", "#");
mc = mc.replaceAll("#2\\/", "#");

View file

@ -215,7 +215,7 @@ public class TableModel extends AbstractTableModel implements ICardGrid {
return c.getDisplayFullName(); // show full name in deck editor table, e.g. adventure with spell name
case 2:
// new svg images version
return ManaSymbols.getStringManaCost(c.getManaCost());
return ManaSymbols.getClearManaCost(c.getManaCostStr());
/*
// old html images version
String manaCost = "";

View file

@ -24,7 +24,7 @@ public class CardViewColorIdentityComparator implements CardViewComparator {
}
public static FilterMana calcIdentity(CardView cardView) {
return ManaUtil.getColorIdentity(cardView.getColor(), cardView.getManaCost(), cardView.getRules(), null);
return ManaUtil.getColorIdentity(cardView.getColor(), cardView.getManaCostStr(), cardView.getRules(), null);
}
public static int calcHash(CardView cardView) {

View file

@ -97,7 +97,7 @@ public final class GuiDisplayUtil {
j.add(cardText);
TextLines textLines = GuiDisplayUtil.getTextLinesfromCardView(card);
cardText.setText(getRulefromCardView(card, textLines).toString());
cardText.setText(getRulesFromCardView(card, textLines).toString());
descriptionPanel.add(j);
@ -227,11 +227,8 @@ public final class GuiDisplayUtil {
return "<img src='" + getResourcePath("hint/" + iconName + ".png") + "' alt='" + iconName + "' width=" + symbolSize + " height=" + symbolSize + ">";
}
public static StringBuilder getRulefromCardView(CardView card, TextLines textLines) {
String manaCost = "";
for (String m : card.getManaCost()) {
manaCost += m;
}
public static StringBuilder getRulesFromCardView(CardView card, TextLines textLines) {
String manaCost = card.getManaCostStr();
String castingCost = UI.getDisplayManaCost(manaCost);
castingCost = ManaSymbols.replaceSymbolsWithHTML(castingCost, ManaSymbols.Type.TOOLTIP);
@ -347,9 +344,9 @@ public final class GuiDisplayUtil {
rule.append("<tr><td valign='top'><b>");
rule.append(card.getLeftSplitName());
rule.append("</b></td><td align='right' valign='top' style='width:");
rule.append(card.getLeftSplitCosts().getSymbols().size() * GUISizeHelper.symbolTooltipSize + 1);
rule.append(ManaSymbols.getClearManaSymbolsCount(card.getLeftSplitCostsStr()) * GUISizeHelper.symbolTooltipSize + 1);
rule.append("px'>");
rule.append(card.getLeftSplitCosts().getText());
rule.append(card.getLeftSplitCostsStr());
rule.append("</td></tr></table>");
for (String ruling : card.getLeftSplitRules()) {
if (ruling != null && !ruling.replace(".", "").trim().isEmpty()) {
@ -362,9 +359,9 @@ public final class GuiDisplayUtil {
rule.append("<tr><td valign='top'><b>");
rule.append(card.getRightSplitName());
rule.append("</b></td><td align='right' valign='top' style='width:");
rule.append(card.getRightSplitCosts().getSymbols().size() * GUISizeHelper.symbolTooltipSize + 1);
rule.append(ManaSymbols.getClearManaSymbolsCount(card.getRightSplitCostsStr()) * GUISizeHelper.symbolTooltipSize + 1);
rule.append("px'>");
rule.append(card.getRightSplitCosts().getText());
rule.append(card.getRightSplitCostsStr());
rule.append("</td></tr></table>");
for (String ruling : card.getRightSplitRules()) {
if (ruling != null && !ruling.replace(".", "").trim().isEmpty()) {