Small perf: find() instead of filter() for retreat (#3277)

## Description:

Only need find() instead of filter() in orderRetreat and executeRetreat,
since we just need the first hit. Small perf win.

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

## Please put your Discord username so you can be contacted if a bug or
regression is found:

tryout33
This commit is contained in:
VariableVince
2026-02-23 04:54:10 +01:00
committed by GitHub
parent b1c4c9723c
commit 1d73401c72
+6 -6
View File
@@ -366,20 +366,20 @@ export class PlayerImpl implements Player {
this.mg.conquer(this, tile);
}
orderRetreat(id: string) {
const attack = this._outgoingAttacks.filter((attack) => attack.id() === id);
if (!attack || !attack[0]) {
const attack = this._outgoingAttacks.find((attack) => attack.id() === id);
if (!attack) {
console.warn(`Didn't find outgoing attack with id ${id}`);
return;
}
attack[0].orderRetreat();
attack.orderRetreat();
}
executeRetreat(id: string): void {
const attack = this._outgoingAttacks.filter((attack) => attack.id() === id);
const attack = this._outgoingAttacks.find((attack) => attack.id() === id);
// Execution is delayed so it's not an error that the attack does not exist.
if (!attack || !attack[0]) {
if (!attack) {
return;
}
attack[0].executeRetreat();
attack.executeRetreat();
}
relinquish(tile: TileRef) {
if (this.mg.owner(tile) !== this) {