Skip to content

Commit

Permalink
Don't create temp arraylists for CasualtyDetails. (#11833)
Browse files Browse the repository at this point in the history
  • Loading branch information
asvitkine authored Jul 29, 2023
1 parent 9d0f075 commit 7b90506
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import games.strategy.triplea.delegate.battle.steps.fire.SelectCasualties;
import games.strategy.triplea.delegate.battle.steps.fire.SelectMainBattleCasualties;
import games.strategy.triplea.delegate.data.CasualtyDetails;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -161,8 +160,7 @@ public void execute(final ExecutionStack stack, final IDelegateBridge bridge) {
final FireRoundState fireRoundState = new FireRoundState();
fireRoundState.setDice(dice);
fireRoundState.setCasualties(
new CasualtyDetails(
new ArrayList<>(killed), new ArrayList<>(damaged), confirmOwnCasualties));
new CasualtyDetails(killed, damaged, confirmOwnCasualties));
new MarkCasualties(
battle,
battle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class CasualtyDetails extends CasualtyList {
* @param autoCalculated whether casualties should be selected automatically
*/
public CasualtyDetails(
final List<Unit> killed, final List<Unit> damaged, final boolean autoCalculated) {
final Collection<Unit> killed, final Collection<Unit> damaged, final boolean autoCalculated) {
super(killed, damaged);
this.autoCalculated = autoCalculated;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class CasualtyList implements Serializable {
*
* @param damaged (can have multiple of the same unit, to show multiple hits to that unit)
*/
public CasualtyList(final List<Unit> killed, final List<Unit> damaged) {
public CasualtyList(final Collection<Unit> killed, final Collection<Unit> damaged) {
checkNotNull(killed);
checkNotNull(damaged);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
import games.strategy.triplea.settings.AbstractClientSettingTestCase;
import games.strategy.triplea.util.TransportUtils;
import games.strategy.triplea.xml.TestMapGameData;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -1384,8 +1383,7 @@ void testAttackDestroyerAndSubsAgainstSubAndDestroyer() {
bridge,
invocation -> {
final Collection<Unit> selectFrom = invocation.getArgument(0);
return new CasualtyDetails(
List.of(selectFrom.iterator().next()), new ArrayList<>(), false);
return new CasualtyDetails(List.of(selectFrom.iterator().next()), List.of(), false);
});
whenGetRandom(bridge)
.thenAnswer(withValues(0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1228,8 +1228,7 @@ void testAttackDestroyerAndSubsAgainstSubAndDestroyer() {
bridge,
invocation -> {
final Collection<Unit> selectFrom = invocation.getArgument(0);
return new CasualtyDetails(
List.of(selectFrom.iterator().next()), new ArrayList<>(), false);
return new CasualtyDetails(List.of(selectFrom.iterator().next()), List.of(), false);
});
// attacking subs sneak attack and hit
// no chance to return fire
Expand Down Expand Up @@ -1290,7 +1289,7 @@ void testLimitBombardToNumberOfUnloaded() {
final int hitsRemaining = invocation.getArgument(2);
return new CasualtyDetails(
selectFrom.stream().limit(hitsRemaining).collect(Collectors.toList()),
new ArrayList<>(),
List.of(),
false);
});
// Show that bombard casualties can return fire
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import games.strategy.triplea.delegate.power.calculator.CombatValueBuilder;
import games.strategy.triplea.xml.TestMapGameData;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -65,7 +64,7 @@ private void givenRemotePlayerWillSelectStrategicBombersForCasualties() {
final int count = invocation.getArgument(2);
final List<Unit> selected =
CollectionUtils.getNMatches(selectFrom, count, Matches.unitIsStrategicBomber());
return new CasualtyDetails(selected, new ArrayList<>(), false);
return new CasualtyDetails(selected, List.of(), false);
});
}

Expand Down

0 comments on commit 7b90506

Please sign in to comment.