performance: improved CPU usage in games with big amount of permanents (related to #11285)

This commit is contained in:
Oleg Agafonov 2023-11-07 01:14:07 +04:00
parent 1f50f95f8b
commit 70c79fd6a6
4 changed files with 14 additions and 5 deletions

View file

@ -24,11 +24,16 @@ public class AbilitiesImpl<T extends Ability> extends ArrayList<T> implements Ab
private static final ThreadLocalStringBuilder threadLocalBuilder = new ThreadLocalStringBuilder(200);
public AbilitiesImpl() {
// fast constructor
}
public AbilitiesImpl(T... abilities) {
Collections.addAll(this, abilities);
}
public AbilitiesImpl(final AbilitiesImpl<T> abilities) {
this.ensureCapacity(abilities.size());
for (T ability : abilities) {
this.add((T) ability.copy());
}

View file

@ -12,7 +12,7 @@ public abstract class CostImpl implements Cost {
protected UUID id;
protected String text;
protected boolean paid;
protected Targets targets;
protected Targets targets; // TODO: optimize performance - use private and null by default
public CostImpl() {
id = UUID.randomUUID();

View file

@ -45,6 +45,7 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
private ManaCostsImpl(final ManaCostsImpl<T> costs) {
this.id = costs.id;
this.text = costs.text;
this.ensureCapacity(costs.size());
for (T cost : costs) {
this.add(cost.copy());
}

View file

@ -4,9 +4,9 @@ import mage.abilities.Ability;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.target.targetpointer.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@ -16,13 +16,16 @@ import java.util.stream.Collectors;
*/
public class Targets extends ArrayList<Target> {
public Targets() {
// fast constructor
}
public Targets(Target... targets) {
for (Target target : targets) {
this.add(target);
}
this.addAll(Arrays.asList(targets));
}
protected Targets(final Targets targets) {
this.ensureCapacity(targets.size());
for (Target target : targets) {
this.add(target.copy());
}