From 09a4f17270e0d4a8960754ce9b29429c39095187 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 18 Feb 2026 22:12:15 +0000 Subject: [PATCH] =?UTF-8?q?Optimize=20zones=20restoration=20with=20O(n)=20?= =?UTF-8?q?map=20lookup=20instead=20of=20O(n=C2=B2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com> --- public/modules/ui/heightmap-editor.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/public/modules/ui/heightmap-editor.js b/public/modules/ui/heightmap-editor.js index e5272c35..d98c1c3f 100644 --- a/public/modules/ui/heightmap-editor.js +++ b/public/modules/ui/heightmap-editor.js @@ -443,9 +443,16 @@ function editHeightmap(options) { Lakes.defineNames(); } + const gridToPackMap = new Map(); + for (const i of pack.cells.i) { + const g = pack.cells.g[i]; + if (!gridToPackMap.has(g)) gridToPackMap.set(g, []); + gridToPackMap.get(g).push(i); + } + for (const zone of pack.zones) { if (!zone.gridCells || !zone.gridCells.length) continue; - zone.cells = pack.cells.i.filter(i => zone.gridCells.includes(pack.cells.g[i])); + zone.cells = zone.gridCells.flatMap(g => gridToPackMap.get(g) || []); delete zone.gridCells; }