perf(hooks,tools): optimize string operations and reduce redundant iterations
- output-renderer, hashline-edit-diff: replace str += with array join (H2) - auto-slash-command: single-pass Map grouping instead of 6x filter (M1) - comment-checker: hoist Zod schema to module scope (M2) - session-last-agent: reverse iterate sorted array instead of sort+reverse (L2)
This commit is contained in:
@@ -4,7 +4,7 @@ export function generateHashlineDiff(oldContent: string, newContent: string, fil
|
||||
const oldLines = oldContent.split("\n")
|
||||
const newLines = newContent.split("\n")
|
||||
|
||||
let diff = `--- ${filePath}\n+++ ${filePath}\n`
|
||||
const parts: string[] = [`--- ${filePath}\n+++ ${filePath}\n`]
|
||||
const maxLines = Math.max(oldLines.length, newLines.length)
|
||||
|
||||
for (let i = 0; i < maxLines; i += 1) {
|
||||
@@ -14,18 +14,18 @@ export function generateHashlineDiff(oldContent: string, newContent: string, fil
|
||||
const hash = computeLineHash(lineNum, newLine)
|
||||
|
||||
if (i >= oldLines.length) {
|
||||
diff += `+ ${lineNum}#${hash}|${newLine}\n`
|
||||
parts.push(`+ ${lineNum}#${hash}|${newLine}\n`)
|
||||
continue
|
||||
}
|
||||
if (i >= newLines.length) {
|
||||
diff += `- ${lineNum}# |${oldLine}\n`
|
||||
parts.push(`- ${lineNum}# |${oldLine}\n`)
|
||||
continue
|
||||
}
|
||||
if (oldLine !== newLine) {
|
||||
diff += `- ${lineNum}# |${oldLine}\n`
|
||||
diff += `+ ${lineNum}#${hash}|${newLine}\n`
|
||||
parts.push(`- ${lineNum}# |${oldLine}\n`)
|
||||
parts.push(`+ ${lineNum}#${hash}|${newLine}\n`)
|
||||
}
|
||||
}
|
||||
|
||||
return diff
|
||||
return parts.join("")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user