@@ -34,8 +34,8 @@ const (
34
34
DiffInsert Operation = 1
35
35
// DiffEqual item represents an equal diff.
36
36
DiffEqual Operation = 0
37
- //IndexSeperator is used to seperate the array indexes in an index string
38
- IndexSeperator = ","
37
+ //IndexSeparator is used to seperate the array indexes in an index string
38
+ IndexSeparator = ","
39
39
)
40
40
41
41
// Diff represents one diff operation
@@ -122,7 +122,7 @@ func (dmp *DiffMatchPatch) diffMainRunes(text1, text2 []rune, checklines bool, d
122
122
123
123
// Restore the prefix and suffix.
124
124
if len (commonprefix ) != 0 {
125
- diffs = append ([]Diff {Diff {DiffEqual , string (commonprefix )}}, diffs ... )
125
+ diffs = append ([]Diff {{DiffEqual , string (commonprefix )}}, diffs ... )
126
126
}
127
127
if len (commonsuffix ) != 0 {
128
128
diffs = append (diffs , Diff {DiffEqual , string (commonsuffix )})
@@ -167,8 +167,8 @@ func (dmp *DiffMatchPatch) diffCompute(text1, text2 []rune, checklines bool, dea
167
167
// Single character string.
168
168
// After the previous speedup, the character can't be an equality.
169
169
return []Diff {
170
- Diff {DiffDelete , string (text1 )},
171
- Diff {DiffInsert , string (text2 )},
170
+ {DiffDelete , string (text1 )},
171
+ {DiffInsert , string (text2 )},
172
172
}
173
173
// Check to see if the problem can be split in two.
174
174
} else if hm := dmp .diffHalfMatch (text1 , text2 ); hm != nil {
@@ -370,8 +370,8 @@ func (dmp *DiffMatchPatch) diffBisect(runes1, runes2 []rune, deadline time.Time)
370
370
}
371
371
// Diff took too long and hit the deadline or number of diffs equals number of characters, no commonality at all.
372
372
return []Diff {
373
- Diff {DiffDelete , string (runes1 )},
374
- Diff {DiffInsert , string (runes2 )},
373
+ {DiffDelete , string (runes1 )},
374
+ {DiffInsert , string (runes2 )},
375
375
}
376
376
}
377
377
@@ -406,7 +406,7 @@ func (dmp *DiffMatchPatch) DiffLinesToRunes(text1, text2 string) ([]rune, []rune
406
406
func (dmp * DiffMatchPatch ) DiffCharsToLines (diffs []Diff , lineArray []string ) []Diff {
407
407
hydrated := make ([]Diff , 0 , len (diffs ))
408
408
for _ , aDiff := range diffs {
409
- chars := strings .Split (aDiff .Text , IndexSeperator )
409
+ chars := strings .Split (aDiff .Text , IndexSeparator )
410
410
text := make ([]string , len (chars ))
411
411
412
412
for i , r := range chars {
@@ -993,7 +993,7 @@ func (dmp *DiffMatchPatch) DiffCleanupMerge(diffs []Diff) []Diff {
993
993
if x > 0 && diffs [x - 1 ].Type == DiffEqual {
994
994
diffs [x - 1 ].Text += string (textInsert [:commonlength ])
995
995
} else {
996
- diffs = append ([]Diff {Diff {DiffEqual , string (textInsert [:commonlength ])}}, diffs ... )
996
+ diffs = append ([]Diff {{DiffEqual , string (textInsert [:commonlength ])}}, diffs ... )
997
997
pointer ++
998
998
}
999
999
textInsert = textInsert [commonlength :]
@@ -1317,20 +1317,16 @@ func (dmp *DiffMatchPatch) diffLinesToStrings(text1, text2 string) (string, stri
1317
1317
strIndexArray1 := dmp .diffLinesToStringsMunge (text1 , & lineArray )
1318
1318
strIndexArray2 := dmp .diffLinesToStringsMunge (text2 , & lineArray )
1319
1319
1320
- //Adding a delimter to later get the strings as array
1321
- str1 := strings .Join (strIndexArray1 [:], IndexSeperator )
1322
- str2 := strings .Join (strIndexArray2 [:], IndexSeperator )
1323
-
1324
- return str1 , str2 , lineArray
1320
+ return intArrayToString (strIndexArray1 ), intArrayToString (strIndexArray2 ), lineArray
1325
1321
}
1326
1322
1327
1323
// diffLinesToStringsMunge splits a text into an array of strings, and reduces the texts to a []string.
1328
- func (dmp * DiffMatchPatch ) diffLinesToStringsMunge (text string , lineArray * []string ) []string {
1324
+ func (dmp * DiffMatchPatch ) diffLinesToStringsMunge (text string , lineArray * []string ) []uint32 {
1329
1325
// 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.
1330
1326
lineHash := map [string ]int {} // e.g. lineHash['Hello\n'] == 4
1331
1327
lineStart := 0
1332
1328
lineEnd := - 1
1333
- strs := []string {}
1329
+ strs := []uint32 {}
1334
1330
1335
1331
for lineEnd < len (text )- 1 {
1336
1332
lineEnd = indexOf (text , "\n " , lineStart )
@@ -1344,11 +1340,11 @@ func (dmp *DiffMatchPatch) diffLinesToStringsMunge(text string, lineArray *[]str
1344
1340
lineValue , ok := lineHash [line ]
1345
1341
1346
1342
if ok {
1347
- strs = append (strs , strconv . Itoa (lineValue ))
1343
+ strs = append (strs , uint32 (lineValue ))
1348
1344
} else {
1349
1345
* lineArray = append (* lineArray , line )
1350
1346
lineHash [line ] = len (* lineArray ) - 1
1351
- strs = append (strs , strconv . Itoa (len (* lineArray )- 1 ))
1347
+ strs = append (strs , uint32 (len (* lineArray )- 1 ))
1352
1348
}
1353
1349
}
1354
1350
0 commit comments