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 <roo-code@z.ewheeler.org>
This commit is contained in:
Eric Wheeler 2025-03-07 21:50:33 -08:00
parent 5c9f7722b6
commit e3b682f119

View file

@ -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)