From 17e3b84bcce9c9fce68a114cbec8dd8290bee796 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 27 May 2026 18:17:17 +0000 Subject: [PATCH] perf: use single loop for cellsNeeded sum in BufferReflow Replace map().reduce() with one accumulator loop in reflowSmallerGetNewLineLengths to avoid allocating an intermediate array when summing wrapped line trimmed lengths. Fixes #5942 Co-authored-by: Daniel Imms --- src/common/buffer/BufferReflow.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/common/buffer/BufferReflow.ts b/src/common/buffer/BufferReflow.ts index 44aa0976f..45a194711 100644 --- a/src/common/buffer/BufferReflow.ts +++ b/src/common/buffer/BufferReflow.ts @@ -178,7 +178,10 @@ export function reflowLargerApplyNewLayout(lines: CircularList, new */ export function reflowSmallerGetNewLineLengths(wrappedLines: BufferLine[], oldCols: number, newCols: number): number[] { const newLineLengths: number[] = []; - const cellsNeeded = wrappedLines.map((l, i) => getWrappedLineTrimmedLength(wrappedLines, i, oldCols)).reduce((p, c) => p + c); + let cellsNeeded = 0; + for (let i = 0; i < wrappedLines.length; i++) { + cellsNeeded += getWrappedLineTrimmedLength(wrappedLines, i, oldCols); + } // Use srcCol and srcLine to find the new wrapping point, use that to get the cellsAvailable and // linesNeeded