From 5e11bb4027a65a32f5cfc388b78453ea16e436ba Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Mon, 24 Nov 2025 18:18:16 +0100 Subject: [PATCH] chore: pre-allocate dots arrays --- intersect.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/intersect.js b/intersect.js index 3091685..1bec192 100644 --- a/intersect.js +++ b/intersect.js @@ -328,24 +328,25 @@ function findBezierIntersections(bez1, bez2, justCount) { n1 = isLine(bez1) ? 1 : ~~(l1 / 5) || 1, // eslint-disable-next-line no-bitwise n2 = isLine(bez2) ? 1 : ~~(l2 / 5) || 1, - dots1 = [], - dots2 = [], + dots1 = new Array(n1 + 1), + dots2 = new Array(n2 + 1), xy = {}, - res = justCount ? 0 : []; + res = justCount ? 0 : [], + i, j; - for (var i = 0; i < n1 + 1; i++) { + for (i = 0; i < n1 + 1; i++) { var p = findDotsAtSegment(...bez1, i / n1); - dots1.push({ x: p.x, y: p.y, t: i / n1 }); + dots1[i] = { x: p.x, y: p.y, t: i / n1 }; } for (i = 0; i < n2 + 1; i++) { p = findDotsAtSegment(...bez2, i / n2); - dots2.push({ x: p.x, y: p.y, t: i / n2 }); + dots2[i] = { x: p.x, y: p.y, t: i / n2 }; } for (i = 0; i < n1; i++) { - for (var j = 0; j < n2; j++) { + for (j = 0; j < n2; j++) { var di = dots1[i], di1 = dots1[i + 1], dj = dots2[j],