From e3b682f1193769c1eb986a353e2e2ae915b35445 Mon Sep 17 00:00:00 2001 From: Eric Wheeler Date: Fri, 7 Mar 2025 21:50:33 -0800 Subject: [PATCH] perf: use string instead of array for terminal output Use a string instead of array for terminal output since it is faster than splitting and joining. Also note that 'line' events may contain multiple lines, so concatenating directly is more efficient. Signed-off-by: Eric Wheeler --- src/core/Cline.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/core/Cline.ts b/src/core/Cline.ts index 87800e27ae..6729fa326d 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -964,9 +964,9 @@ export class Cline { } } - let lines: string[] = [] + let result = "" process.on("line", (line) => { - lines.push(line) + result += line if (!didContinue) { sendCommandOutput(line) } else { @@ -978,9 +978,7 @@ export class Cline { let exitDetails: ExitCodeDetails | undefined process.once("completed", (output?: string) => { // Use provided output if available, otherwise keep existing result. - if (output) { - lines = output.split("\n") - } + result = output || result completed = true }) @@ -1004,8 +1002,7 @@ export class Cline { await delay(50) const { terminalOutputLineLimit } = (await this.providerRef.deref()?.getState()) ?? {} - const output = truncateOutput(lines.join("\n"), terminalOutputLineLimit) - const result = output.trim() + result = truncateOutput(result, terminalOutputLineLimit) if (userFeedback) { await this.say("user_feedback", userFeedback.text, userFeedback.images)