No per-frame allocations in the 'doesn't connect' marks (t87)

This commit is contained in:
2026-10-29 22:06:33 -04:00
parent f88035a58f
commit de6d2c1b33
3 changed files with 26 additions and 6 deletions
+13 -4
View File
@@ -108,16 +108,25 @@ function joinSnap(code, v, cells) {
// A drop join counts as connected. The moved block is tried through a small override view of
// `planned`, so ghost maps are never copied.
const NO_PIECE = [0, 0];
// Synchronous join queries never retain this scratch view or call nearMiss recursively.
const NEAR_MISS_VIEW = {
source: -1, moved: -1, planned: null, entry: [0, 0],
get(k) {
return k === this.source ? NO_PIECE : k === this.moved ? this.entry : this.planned ? this.planned.get(k) : undefined;
},
has(k) { return this.get(k) !== undefined; }
};
function nearMiss(bx, by, end, planned = null) {
const b = by * BW + bx, p = planned && planned.get(b), code = p ? p[0] : blockP[b], v = p ? p[1] : blockV[b];
const own = pieceEnds(code, v);
if (!own[end] || endJoin(bx, by, end, planned) >= 0) return 0;
const entry = [code, v];
for (const dy of [-1, 1]) {
const view = NEAR_MISS_VIEW;
view.source = b; view.planned = planned;
view.entry[0] = code; view.entry[1] = v;
for (let dy = -1; dy <= 1; dy += 2) {
const y = by + dy, nb = y * BW + bx;
if (y < 0 || y >= BH || blockP[nb] || (planned && planned.get(nb))) continue;
const view = { get: k => k === b ? NO_PIECE : k === nb ? entry : planned ? planned.get(k) : undefined };
view.has = k => view.get(k) !== undefined;
view.moved = nb;
const j = endJoin(bx, y, end, view);
if (j >= 0 && !joinIsDrop(bx, y, end, j, view) && (own[end].diagonal || endAt(j >> 1, j & 1, view).diagonal)) return dy;
}