Files
oh-my-opencode/src/tools/hashline-edit/hashline-edit-diff.ts
T
YeonGyu-Kim 90aa3a306c 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)
2026-03-18 14:19:12 +09:00

32 lines
948 B
TypeScript

import { computeLineHash } from "./hash-computation"
export function generateHashlineDiff(oldContent: string, newContent: string, filePath: string): string {
const oldLines = oldContent.split("\n")
const newLines = newContent.split("\n")
const parts: string[] = [`--- ${filePath}\n+++ ${filePath}\n`]
const maxLines = Math.max(oldLines.length, newLines.length)
for (let i = 0; i < maxLines; i += 1) {
const oldLine = oldLines[i] ?? ""
const newLine = newLines[i] ?? ""
const lineNum = i + 1
const hash = computeLineHash(lineNum, newLine)
if (i >= oldLines.length) {
parts.push(`+ ${lineNum}#${hash}|${newLine}\n`)
continue
}
if (i >= newLines.length) {
parts.push(`- ${lineNum}# |${oldLine}\n`)
continue
}
if (oldLine !== newLine) {
parts.push(`- ${lineNum}# |${oldLine}\n`)
parts.push(`+ ${lineNum}#${hash}|${newLine}\n`)
}
}
return parts.join("")
}