Optimization to avoid excessive allocations.

This commit is contained in:
Myrd
2014-12-30 21:30:25 +00:00
parent 1a8ab8dfd0
commit 4096643769

View File

@@ -54,7 +54,16 @@ import java.util.Map;
* @version $Id$ * @version $Id$
*/ */
public final class GameActionUtil { public final class GameActionUtil {
// Cache these instead of generating them on the fly, to avoid excessive allocations every time
// static abilities are checked.
private static final String[] BASIC_LAND_ABILITIES = new String[MagicColor.WUBRG.length];
static {
for (int i = 0; i < MagicColor.WUBRG.length; i++ ) {
String color = MagicColor.toShortString(MagicColor.WUBRG[i]);
BASIC_LAND_ABILITIES[i] = "AB$ Mana | Cost$ T | Produced$ " + color +
" | SpellDescription$ Add {" + color + "} to your mana pool.";
}
}
private GameActionUtil() { private GameActionUtil() {
throw new AssertionError(); throw new AssertionError();
@@ -130,8 +139,7 @@ public final class GameActionUtil {
// add all appropriate mana abilities based on current types // add all appropriate mana abilities based on current types
for (int i = 0; i < MagicColor.WUBRG.length; i++ ) { for (int i = 0; i < MagicColor.WUBRG.length; i++ ) {
String landType = MagicColor.Constant.BASIC_LANDS.get(i); String landType = MagicColor.Constant.BASIC_LANDS.get(i);
String color = MagicColor.toShortString(MagicColor.WUBRG[i]); String abString = BASIC_LAND_ABILITIES[i];
String abString = "AB$ Mana | Cost$ T | Produced$ " + color + " | SpellDescription$ Add {" + color + "} to your mana pool.";
for (final Card land : lands) { for (final Card land : lands) {
if (land.getType().hasSubtype(landType)) { if (land.getType().hasSubtype(landType)) {
final SpellAbility sa = AbilityFactory.getAbility(abString, land); final SpellAbility sa = AbilityFactory.getAbility(abString, land);