Skip to content

Commit 71e2760

Browse files
akovaskirwcarlsen
authored andcommitted
concat function is not needed, builtin append works in place
1 parent f23538d commit 71e2760

File tree

2 files changed

+2
-11
lines changed

2 files changed

+2
-11
lines changed

diff/dmp.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,6 @@ var (
6464
blanklineStartRegex_ = regexp.MustCompile(`^\r?\n\r?\n`)
6565
)
6666

67-
func concat(old1, old2 []Diff) []Diff {
68-
newslice := make([]Diff, len(old1)+len(old2))
69-
copy(newslice, old1)
70-
copy(newslice[len(old1):], old2)
71-
return newslice
72-
}
73-
7467
func splice(slice []Diff, index int, amount int, elements ...Diff) []Diff {
7568
return append(slice[:index], append(elements, slice[index+amount:]...)...)
7669
}
@@ -334,9 +327,7 @@ func (dmp *DiffMatchPatch) diffCompute(text1 string, text2 string, checklines bo
334327
diffs_a := dmp.DiffMain(text1_a, text2_a, checklines, deadline)
335328
diffs_b := dmp.DiffMain(text1_b, text2_b, checklines, deadline)
336329
// Merge the results.
337-
// TODO: Concat should accept several arguments
338-
concat1 := concat(diffs_a, []Diff{Diff{DiffEqual, mid_common}})
339-
return concat(concat1, diffs_b)
330+
return append(diffs_a, append([]Diff{Diff{DiffEqual, mid_common}}, diffs_b...)...)
340331
}
341332
if checklines && utf8.RuneCountInString(text1) > 100 && utf8.RuneCountInString(text2) > 100 {
342333
return dmp.diffLineMode(text1, text2, deadline)

diff/dmp_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ func Test_diffMain(t *testing.T) {
854854
Diff{DiffInsert, "\u0000"}}
855855

856856
assertDiffEqual(t, diffs, dmp.DiffMain("ax\t", "\u0680x\u0000", false))
857-
assertDiffEqual(diffs, dmp.DiffMain("ax\t", "\u0680x\u0000", false))
857+
assertDiffEqual(t, diffs, dmp.DiffMain("ax\t", "\u0680x\u0000", false))
858858
diffs = []Diff{Diff{DiffDelete, "1"}, Diff{DiffEqual, "a"}, Diff{DiffDelete, "y"}, Diff{DiffEqual, "b"}, Diff{DiffDelete, "2"}, Diff{DiffInsert, "xab"}}
859859
assertDiffEqual(t, diffs, dmp.DiffMain("1ayb2", "abxab", false))
860860

0 commit comments

Comments
 (0)