A line diff does not read a document like a person. It converts each normalized text into an ordered sequence of complete line tokens, finds a longest sequence shared by both sides, and explains everything outside that sequence as removals or additions. This produces a precise review map for source snippets, notes and ordinary documents, but it does not decide whether two differently written lines mean the same thing.
A complete line is the atomic unit
TextDiff first normalizes CRLF and lone carriage returns to LF so Windows and Unix line endings do not create a screen full of artificial changes. Each remaining token contains the visible characters of one line and the fact that an LF follows it. The final fact matters: `alpha` and `alpha` followed by a newline are distinct source states. Empty text has no line, while one newline contains one empty terminated line. These explicit rules keep counts reproducible.
The shared spine is a longest common subsequence
A subsequence keeps order but may skip items. If both versions contain `alpha` before `gamma`, those lines can form a shared spine even when one side inserts `delta` between them. Dynamic programming calculates the maximum number of matchable tokens from every remaining pair of positions. Reconstruction then walks that table: matching keys become retained records, skipped original lines become removals and skipped revised lines become additions. The result is a shortest insertion/removal script, not a claim that adjacent removal and addition were authored as one replacement.
Exact work is bounded and meaning stays outside
Two equal large files are cheap after their common prefix is removed. Two unrelated files can require a large comparison table, so TextDiff stops when the unmatched middle would exceed eight million line-pair cells. It asks for smaller sections instead of silently switching algorithms. Even a completed result describes line identity only. Similarity is twice the retained line count divided by both line totals. It is not semantic similarity, plagiarism evidence, authorship detection or approval that an important revision is correct.