@@ -34,7 +34,7 @@ const (
34
34
DiffInsert Operation = 1
35
35
// DiffEqual item represents an equal diff.
36
36
DiffEqual Operation = 0
37
- //IndexSeparator is used to seperate the array indexes in an index string
37
+ // IndexSeparator is used to seperate the array indexes in an index string
38
38
IndexSeparator = ","
39
39
)
40
40
@@ -1168,7 +1168,7 @@ func (dmp *DiffMatchPatch) DiffPrettyText(diffs []Diff) string {
1168
1168
1169
1169
// DiffText1 computes and returns the source text (all equalities and deletions).
1170
1170
func (dmp * DiffMatchPatch ) DiffText1 (diffs []Diff ) string {
1171
- //StringBuilder text = new StringBuilder()
1171
+ // StringBuilder text = new StringBuilder()
1172
1172
var text bytes.Buffer
1173
1173
1174
1174
for _ , aDiff := range diffs {
@@ -1312,18 +1312,19 @@ func (dmp *DiffMatchPatch) DiffFromDelta(text1 string, delta string) (diffs []Di
1312
1312
func (dmp * DiffMatchPatch ) diffLinesToStrings (text1 , text2 string ) (string , string , []string ) {
1313
1313
// '\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.
1314
1314
lineArray := []string {"" } // e.g. lineArray[4] == 'Hello\n'
1315
+ lineHash := make (map [string ]int )
1316
+ lineHash ["" ] = 0
1315
1317
1316
- //Each string has the index of lineArray which it points to
1317
- strIndexArray1 := dmp .diffLinesToStringsMunge (text1 , & lineArray )
1318
- strIndexArray2 := dmp .diffLinesToStringsMunge (text2 , & lineArray )
1318
+ // Each string has the index of lineArray which it points to
1319
+ strIndexArray1 := dmp .diffLinesToStringsMunge (text1 , & lineArray , lineHash )
1320
+ strIndexArray2 := dmp .diffLinesToStringsMunge (text2 , & lineArray , lineHash )
1319
1321
1320
1322
return intArrayToString (strIndexArray1 ), intArrayToString (strIndexArray2 ), lineArray
1321
1323
}
1322
1324
1323
1325
// diffLinesToStringsMunge splits a text into an array of strings, and reduces the texts to a []string.
1324
- func (dmp * DiffMatchPatch ) diffLinesToStringsMunge (text string , lineArray * []string ) []uint32 {
1326
+ func (dmp * DiffMatchPatch ) diffLinesToStringsMunge (text string , lineArray * []string , lineHash map [ string ] int ) []uint32 {
1325
1327
// 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.
1326
- lineHash := map [string ]int {} // e.g. lineHash['Hello\n'] == 4
1327
1328
lineStart := 0
1328
1329
lineEnd := - 1
1329
1330
strs := []uint32 {}
0 commit comments