Skip to content

Commit 4a7cd54

Browse files
committed
fix comments and variable names
1 parent 2d12574 commit 4a7cd54

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

diffmatchpatch/dmp.go

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -511,18 +511,18 @@ func (dmp *DiffMatchPatch) DiffLinesToChars(text1, text2 string) (string, string
511511
return chars1, chars2, lineArray
512512
}
513513

514-
// DiffLinesToChars split two texts into a list of strings. Reduces the texts to a string of
515-
// hashes where each Unicode character represents one line.
514+
// DiffWordsToChars split two texts into a list of strings. Reduces the texts to a string of
515+
// hashes where each Unicode character represents one word.
516516
func (dmp *DiffMatchPatch) DiffWordsToChars(text1, text2 string) (string, string, []string) {
517517
// '\x00' is a valid character, but various debuggers don't like it.
518518
// So we'll insert a junk entry to avoid generating a null character.
519-
lineArray := []string{""} // e.g. lineArray[4] == 'Hello\n'
520-
lineHash := map[string]int{} // e.g. lineHash['Hello\n'] == 4
519+
wordArray := []string{""} // e.g. lineArray[4] == 'Hello\n'
520+
wordHash := map[string]int{} // e.g. lineHash['Hello\n'] == 4
521521

522-
chars1 := dmp.diffWordsToCharsMunge(text1, &lineArray, lineHash)
523-
chars2 := dmp.diffWordsToCharsMunge(text2, &lineArray, lineHash)
522+
chars1 := dmp.diffWordsToCharsMunge(text1, &wordArray, wordHash)
523+
chars2 := dmp.diffWordsToCharsMunge(text2, &wordArray, wordHash)
524524

525-
return chars1, chars2, lineArray
525+
return chars1, chars2, wordArray
526526
}
527527

528528
// diffLinesToCharsMunge splits a text into an array of strings. Reduces the texts to a string of
@@ -559,40 +559,38 @@ func (dmp *DiffMatchPatch) diffLinesToCharsMunge(text string, lineArray *[]strin
559559
return string(runes)
560560
}
561561

562-
// diffLinesToCharsMunge splits a text into an array of strings. Reduces the texts to a string of
563-
// hashes where each Unicode character represents one line.
564-
// Modifies linearray and linehash through being a closure.
565-
func (dmp *DiffMatchPatch) diffWordsToCharsMunge(text string, lineArray *[]string, lineHash map[string]int) string {
566-
// Walk the text, pulling out a substring for each line.
567-
// text.split('\n') would would temporarily double our memory footprint.
568-
// Modifying text would create many large strings to garbage collect.
569-
lineStart := 0
570-
lineEnd := -1
562+
// diffWordsToCharsMunge splits a text into an array of strings. Reduces the texts to a string of
563+
// hashes where each Unicode character represents one word.
564+
// Modifies wordarray and wordhash through being a closure.
565+
func (dmp *DiffMatchPatch) diffWordsToCharsMunge(text string, wordArray *[]string, wordHash map[string]int) string {
566+
// Walk the text, pulling out a substring for each word.
567+
wordStart := 0
568+
wordEnd := -1
571569
runes := []rune{}
572570

573-
for lineEnd < len(text)-1 {
574-
lineIndex := indexOf(text, "\n", lineStart)
575-
wordIndex := indexOf(text, " ", lineStart)
571+
for wordEnd < len(text)-1 {
572+
lineIndex := indexOf(text, "\n", wordStart)
573+
wordIndex := indexOf(text, " ", wordStart)
576574
if lineIndex < wordIndex && lineIndex != -1 || wordIndex == -1 {
577-
lineEnd = lineIndex
575+
wordEnd = lineIndex
578576
} else {
579-
lineEnd = wordIndex
577+
wordEnd = wordIndex
580578
}
581579

582-
if lineEnd == -1 {
583-
lineEnd = len(text) - 1
580+
if wordEnd == -1 {
581+
wordEnd = len(text) - 1
584582
}
585583

586-
line := text[lineStart : lineEnd+1]
587-
lineStart = lineEnd + 1
588-
lineValue_, ok := lineHash[line]
584+
word := text[wordStart : wordEnd+1]
585+
wordStart = wordEnd + 1
586+
wordValue_, ok := wordHash[word]
589587

590588
if ok {
591-
runes = append(runes, rune(lineValue_))
589+
runes = append(runes, rune(wordValue_))
592590
} else {
593-
*lineArray = append(*lineArray, line)
594-
lineHash[line] = len(*lineArray) - 1
595-
runes = append(runes, rune(len(*lineArray)-1))
591+
*wordArray = append(*wordArray, word)
592+
wordHash[word] = len(*wordArray) - 1
593+
runes = append(runes, rune(len(*wordArray)-1))
596594
}
597595
}
598596

0 commit comments

Comments
 (0)