From dda1e6c1a3cf3625a9c4c569a949c7b1421d8981 Mon Sep 17 00:00:00 2001 From: Fabio Pedretti Date: Mon, 5 Oct 2026 14:17:36 +0200 Subject: [PATCH] Use an indexed loop in getClosestPointTo() Iterate with an indexed loop over a local reference to the points array instead of for...of over this.points, which avoids iterator and property lookup overhead in a loop that can run over thousands of points. --- binaries/data/mods/public/maps/random/rmgen/Area.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/binaries/data/mods/public/maps/random/rmgen/Area.js b/binaries/data/mods/public/maps/random/rmgen/Area.js index 3d16cda5f4..2d8b97dd74 100644 --- a/binaries/data/mods/public/maps/random/rmgen/Area.js +++ b/binaries/data/mods/public/maps/random/rmgen/Area.js @@ -25,14 +25,16 @@ Area.prototype.contains = function(point) Area.prototype.getClosestPointTo = function(position) { - if (!this.points.length) + const points = this.points; + if (!points.length) return undefined; - let closestPoint = this.points[0]; + let closestPoint = points[0]; let shortestDistance = Infinity; - for (const point of this.points) + for (let i = 0; i < points.length; ++i) { + const point = points[i]; const currentDistance = point.distanceToSquared(position); if (currentDistance < shortestDistance) {