Small code speed up: Avoid calling getFirstAbility() redundantly.

This was showing up in simulation AI profiles.
This commit is contained in:
asvitkine
2023-01-14 00:53:12 -05:00
parent e0080f8d43
commit 4a8196b373
2 changed files with 7 additions and 6 deletions

View File

@@ -185,7 +185,8 @@ public final class AbilityFactory {
String cost = mapParams.get("Cost"); String cost = mapParams.get("Cost");
if (cost == null) { if (cost == null) {
if (type == AbilityRecordType.Spell) { if (type == AbilityRecordType.Spell) {
if (state.getFirstAbility() != null && state.getFirstAbility().isSpell()) { SpellAbility firstAbility = state.getFirstAbility();
if (firstAbility != null && firstAbility.isSpell()) {
// TODO might remove when Enchant Keyword is refactored // TODO might remove when Enchant Keyword is refactored
System.err.println(state.getName() + " already has Spell using mana cost"); System.err.println(state.getName() + " already has Spell using mana cost");
} }

View File

@@ -2442,14 +2442,14 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
} }
// add As an additional cost to Permanent spells // add As an additional cost to Permanent spells
if (state.getFirstAbility() != null && type.isPermanent()) { SpellAbility first = state.getFirstAbility();
SpellAbility first = state.getFirstAbility(); if (first != null && type.isPermanent()) {
if (first.isSpell()) { if (first.isSpell()) {
Cost cost = first.getPayCosts(); Cost cost = first.getPayCosts();
if (cost != null && !cost.isOnlyManaCost()) { if (cost != null && !cost.isOnlyManaCost()) {
String additionalDesc = ""; String additionalDesc = "";
if (state.getFirstAbility().hasParam("AdditionalDesc")) { if (first.hasParam("AdditionalDesc")) {
additionalDesc = state.getFirstAbility().getParam("AdditionalDesc"); additionalDesc = first.getParam("AdditionalDesc");
} }
sb.append(cost.toString().replace("\n", "")).append(" ").append(additionalDesc); sb.append(cost.toString().replace("\n", "")).append(" ").append(additionalDesc);
sb.append(linebreak); sb.append(linebreak);
@@ -3757,7 +3757,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
public final CardTypeView getOriginalType() { public final CardTypeView getOriginalType() {
return getOriginalType(currentState); return getOriginalType(currentState);
} }
public final CardTypeView getOriginalType(CardState state) { public final CardTypeView getOriginalType(CardState state) {
return state.getType(); return state.getType();
} }