Perf: tradeship spawn (#3240)

## Description:

Please merge for v30 if possible.

Use .find instead of .filter for tradeShipSpawn since we're only looking
for the first (if any) port found at the given tile anyway.

Also just return targetTile instead of getting porr.tile() because
targetTile is tile we found the port on.

Also use no intermediate const, just return right away based on outcome
of units.find.

Found when working on PR #3220. But tradeShipSpawn is out of 3220's
scope since it won't be called by playerImpl buildableUnits() anymore,
it should and will be only ever used by TradeShipExecution via
playerImpl canBuild().

## 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:57:12 +01:00
committed by GitHub
parent d48415ac2a
commit c3a8d06cbb
+3 -7
View File
@@ -1258,13 +1258,9 @@ export class PlayerImpl implements Player {
}
tradeShipSpawn(targetTile: TileRef): TileRef | false {
const spawns = this.units(UnitType.Port).filter(
(u) => u.tile() === targetTile,
);
if (spawns.length === 0) {
return false;
}
return spawns[0].tile();
return this.units(UnitType.Port).find((u) => u.tile() === targetTile)
? targetTile
: false;
}
lastTileChange(): Tick {
return this._lastTileChange;