From c3a8d06cbbf02ca4ea5854506e1ca34912e5b3f7 Mon Sep 17 00:00:00 2001 From: VariableVince <24507472+VariableVince@users.noreply.github.com> Date: Mon, 23 Feb 2026 04:57:12 +0100 Subject: [PATCH] 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 --- src/core/game/PlayerImpl.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/core/game/PlayerImpl.ts b/src/core/game/PlayerImpl.ts index 3d20bc324..cd8ebc05a 100644 --- a/src/core/game/PlayerImpl.ts +++ b/src/core/game/PlayerImpl.ts @@ -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;