From 1938e659ab67ac67942be163d77669ff70cf34c2 Mon Sep 17 00:00:00 2001 From: mappu Date: Tue, 11 Jul 2017 18:07:55 +1200 Subject: [PATCH] diff: remove some empty ins/del instructions --- diff/diff.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/diff/diff.go b/diff/diff.go index 9fcb02b..6b317d8 100644 --- a/diff/diff.go +++ b/diff/diff.go @@ -49,6 +49,12 @@ func Diff(o, n []string) []Instruction { if len(o) == 0 && len(n) == 0 { return []Instruction{} } + if len(o) == 0 { + return []Instruction{{OP_INSERTED, n}} + } + if len(n) == 0 { + return []Instruction{{OP_REMOVED, o}} + } maxl := 0 omax := 0 @@ -79,8 +85,8 @@ func Diff(o, n []string) []Instruction { if maxl == 0 { return []Instruction{ - Instruction{OP_REMOVED, o}, - Instruction{OP_INSERTED, n}, + {OP_REMOVED, o}, + {OP_INSERTED, n}, } }