Skip to content

Commit db9db17

Browse files
authored
Merge branch 'master' into master
2 parents ff0d34b + facec63 commit db9db17

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

diffmatchpatch/diff.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,17 +1310,17 @@ func (dmp *DiffMatchPatch) diffLinesToStrings(text1, text2 string) ([]index, []i
13101310
// '\x00' is a valid character, but various debuggers don't like it. So we'll insert a junk entry to avoid generating a null character.
13111311
lineArray := []string{""} // e.g. lineArray[4] == 'Hello\n'
13121312

1313+
lineHash := make(map[string]int)
13131314
//Each string has the index of lineArray which it points to
1314-
strIndexArray1 := dmp.diffLinesToStringsMunge(text1, &lineArray)
1315-
strIndexArray2 := dmp.diffLinesToStringsMunge(text2, &lineArray)
1315+
strIndexArray1 := dmp.diffLinesToStringsMunge(text1, &lineArray, lineHash)
1316+
strIndexArray2 := dmp.diffLinesToStringsMunge(text2, &lineArray, lineHash)
13161317

13171318
return strIndexArray1, strIndexArray2, lineArray
13181319
}
13191320

13201321
// diffLinesToStringsMunge splits a text into an array of strings, and reduces the texts to a []string.
1321-
func (dmp *DiffMatchPatch) diffLinesToStringsMunge(text string, lineArray *[]string) []index {
1322+
func (dmp *DiffMatchPatch) diffLinesToStringsMunge(text string, lineArray *[]string, lineHash map[string]int) []uint32 {
13221323
// Walk the text, pulling out a substring for each line. text.split('\n') would would temporarily double our memory footprint. Modifying text would create many large strings to garbage collect.
1323-
lineHash := map[string]int{} // e.g. lineHash['Hello\n'] == 4
13241324
lineStart := 0
13251325
lineEnd := -1
13261326
strs := []index{}

diffmatchpatch/diff_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,9 @@ func TestDiffLinesToChars(t *testing.T) {
317317
{"", "alpha\r\nbeta\r\n\r\n\r\n", "", "\x01\x02\x03\x03", []string{"", "alpha\r\n", "beta\r\n", "\r\n"}},
318318
{"a", "b", "\x01", "\x02", []string{"", "a", "b"}},
319319
// Omit final newline.
320-
{"alpha\nbeta\nalpha", "", "\x01\x02\x03", "", []string{"", "alpha\n", "beta\n", "alpha"}},
320+
{"alpha\nbeta\nalpha", "", "1,2,3", "", []string{"", "alpha\n", "beta\n", "alpha"}},
321+
// Same lines in Text1 and Text2
322+
{"abc\ndefg\n12345\n", "abc\ndef\n12345\n678", "1,2,3", "1,4,3,5", []string{"", "abc\n", "defg\n", "12345\n", "def\n", "678"}},
321323
} {
322324
actualChars1, actualChars2, actualLines := dmp.DiffLinesToChars(tc.Text1, tc.Text2)
323325
assert.Equal(t, tc.ExpectedChars1, actualChars1, fmt.Sprintf("Test case #%d, %#v", i, tc))

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require (
55
github.com/kr/pretty v0.1.0 // indirect
66
github.com/stretchr/testify v1.4.0
77
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
8-
gopkg.in/yaml.v2 v2.2.4 // indirect
8+
gopkg.in/yaml.v2 v2.4.0 // indirect
99
)
1010

1111
go 1.12

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
1919
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
2020
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
2121
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
22+
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
23+
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

0 commit comments

Comments
 (0)