@@ -34,7 +34,7 @@ const (
3434 DiffInsert Operation = 1
3535 // DiffEqual item represents an equal diff.
3636 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
3838 IndexSeparator = ","
3939)
4040
@@ -1168,7 +1168,7 @@ func (dmp *DiffMatchPatch) DiffPrettyText(diffs []Diff) string {
11681168
11691169// DiffText1 computes and returns the source text (all equalities and deletions).
11701170func (dmp * DiffMatchPatch ) DiffText1 (diffs []Diff ) string {
1171- //StringBuilder text = new StringBuilder()
1171+ // StringBuilder text = new StringBuilder()
11721172 var text bytes.Buffer
11731173
11741174 for _ , aDiff := range diffs {
@@ -1312,18 +1312,19 @@ func (dmp *DiffMatchPatch) DiffFromDelta(text1 string, delta string) (diffs []Di
13121312func (dmp * DiffMatchPatch ) diffLinesToStrings (text1 , text2 string ) (string , string , []string ) {
13131313 // '\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.
13141314 lineArray := []string {"" } // e.g. lineArray[4] == 'Hello\n'
1315+ lineHash := make (map [string ]int )
1316+ lineHash ["" ] = 0
13151317
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 )
13191321
13201322 return intArrayToString (strIndexArray1 ), intArrayToString (strIndexArray2 ), lineArray
13211323}
13221324
13231325// 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 {
13251327 // 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
13271328 lineStart := 0
13281329 lineEnd := - 1
13291330 strs := []uint32 {}
0 commit comments