forked from External/mage
Refactor: private fields and performance tweaks (#9625)
1a. Make `costs`, `manaCosts`, and `manaCostsToPay` private in `AbilityImpl` with access through getters/setters 1b. fix cost adjuster for imprinted cards affected by the above 2a. Lazy instantiation for rarely used `data` field in `TargetPointerImpl` 3a. Pre-allocate certain array sizes in `Modes` and `CostsImpl` 4a. Make `manaTemplate` private in `BasicManaEffect`, copy when passing outside the class 4b. Don't copy `manaTemplate` in copy constructor since it doesn't change 4c. Add comments explaining copy usage for `manaTemplate` 4d. Remove redundant variable assignment and make fields final --------- Co-authored-by: xenohedron <xenohedron@users.noreply.github.com>
This commit is contained in:
parent
53be4f384e
commit
a2162ec3e7
65 changed files with 262 additions and 196 deletions
|
|
@ -1194,15 +1194,12 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
if (alternateCosts == null) {
|
||||
noMana = true;
|
||||
} else {
|
||||
spellAbility.getManaCosts().clear();
|
||||
spellAbility.getManaCostsToPay().clear();
|
||||
spellAbility.getManaCosts().add(alternateCosts.copy());
|
||||
spellAbility.getManaCostsToPay().add(alternateCosts.copy());
|
||||
}
|
||||
spellAbility.getCosts().clear();
|
||||
if (costs != null) {
|
||||
spellAbility.getCosts().addAll(costs);
|
||||
spellAbility.clearManaCosts();
|
||||
spellAbility.clearManaCostsToPay();
|
||||
spellAbility.addManaCost(alternateCosts.copy());
|
||||
}
|
||||
spellAbility.clearCosts();
|
||||
spellAbility.addCost(costs);
|
||||
}
|
||||
clearCastSourceIdManaCosts(); // TODO: test multiple alternative cost for different cards as same time
|
||||
|
||||
|
|
@ -3620,8 +3617,8 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
|
||||
// alternative cost reduce
|
||||
copyAbility = ability.copy();
|
||||
copyAbility.getManaCostsToPay().clear();
|
||||
copyAbility.getManaCostsToPay().addAll(manaCosts.copy());
|
||||
copyAbility.clearManaCostsToPay();
|
||||
copyAbility.addManaCostsToPay(manaCosts.copy());
|
||||
copyAbility.adjustCosts(game);
|
||||
game.getContinuousEffects().costModification(copyAbility, game);
|
||||
|
||||
|
|
@ -3686,12 +3683,12 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
|
||||
// alternative cost reduce
|
||||
copyAbility = ability.copy();
|
||||
copyAbility.getManaCostsToPay().clear();
|
||||
copyAbility.clearManaCostsToPay();
|
||||
// TODO: IDE warning:
|
||||
// Unchecked assignment: 'mage.abilities.costs.mana.ManaCosts' to
|
||||
// 'java.util.Collection<? extends mage.abilities.costs.mana.ManaCost>'.
|
||||
// Reason: 'manaCosts' has raw type, so result of copy is erased
|
||||
copyAbility.getManaCostsToPay().addAll(manaCosts.copy());
|
||||
copyAbility.addManaCostsToPay(manaCosts.copy());
|
||||
copyAbility.adjustCosts(game);
|
||||
game.getContinuousEffects().costModification(copyAbility, game);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue