From f560430efe865eddb5ad3535a5bd84dd915654c5 Mon Sep 17 00:00:00 2001 From: mappu Date: Tue, 11 Jul 2017 18:25:49 +1200 Subject: [PATCH] diff: correctness --- diff/diff.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/diff/diff.go b/diff/diff.go index 6b317d8..0633c18 100644 --- a/diff/diff.go +++ b/diff/diff.go @@ -46,6 +46,7 @@ type twoints struct { } func Diff(o, n []string) []Instruction { + if len(o) == 0 && len(n) == 0 { return []Instruction{} } @@ -91,9 +92,7 @@ func Diff(o, n []string) []Instruction { } ret := Diff(o[:omax], n[:nmax]) - if maxl != nmax { - ret = append(ret, Instruction{OP_UNCHANGED, n[nmax : maxl-nmax]}) - } + ret = append(ret, Instruction{OP_UNCHANGED, n[nmax : nmax+maxl]}) ret = append(ret, Diff(o[omax+maxl:], n[nmax+maxl:])...) return ret