@@ -178,7 +178,10 @@ func (dmp *DiffMatchPatch) diffCompute(text1, text2 []rune, checklines bool, dea
178
178
diffsA := dmp .diffMainRunes (text1A , text2A , checklines , deadline )
179
179
diffsB := dmp .diffMainRunes (text1B , text2B , checklines , deadline )
180
180
// Merge the results.
181
- return append (diffsA , append ([]Diff {Diff {DiffEqual , string (midCommon )}}, diffsB ... )... )
181
+ diffs := diffsA
182
+ diffs = append (diffs , Diff {DiffEqual , string (midCommon )})
183
+ diffs = append (diffs , diffsB ... )
184
+ return diffs
182
185
} else if checklines && len (text1 ) > 100 && len (text2 ) > 100 {
183
186
return dmp .diffLineMode (text1 , text2 , deadline )
184
187
}
@@ -685,9 +688,7 @@ func (dmp *DiffMatchPatch) DiffCleanupSemantic(diffs []Diff) []Diff {
685
688
(len (lastequality ) <= difference2 ) {
686
689
// Duplicate record.
687
690
insPoint := equalities .data
688
- diffs = append (
689
- diffs [:insPoint ],
690
- append ([]Diff {Diff {DiffDelete , lastequality }}, diffs [insPoint :]... )... )
691
+ diffs = splice (diffs , insPoint , 0 , Diff {DiffDelete , lastequality })
691
692
692
693
// Change second copy to insert.
693
694
diffs [insPoint + 1 ].Type = DiffInsert
@@ -738,10 +739,7 @@ func (dmp *DiffMatchPatch) DiffCleanupSemantic(diffs []Diff) []Diff {
738
739
float64 (overlapLength1 ) >= float64 (len (insertion ))/ 2 {
739
740
740
741
// Overlap found. Insert an equality and trim the surrounding edits.
741
- diffs = append (
742
- diffs [:pointer ],
743
- append ([]Diff {Diff {DiffEqual , insertion [:overlapLength1 ]}}, diffs [pointer :]... )... )
744
-
742
+ diffs = splice (diffs , pointer , 0 , Diff {DiffEqual , insertion [:overlapLength1 ]})
745
743
diffs [pointer - 1 ].Text =
746
744
deletion [0 : len (deletion )- overlapLength1 ]
747
745
diffs [pointer + 1 ].Text = insertion [overlapLength1 :]
@@ -752,10 +750,7 @@ func (dmp *DiffMatchPatch) DiffCleanupSemantic(diffs []Diff) []Diff {
752
750
float64 (overlapLength2 ) >= float64 (len (insertion ))/ 2 {
753
751
// Reverse overlap found. Insert an equality and swap and trim the surrounding edits.
754
752
overlap := Diff {DiffEqual , deletion [:overlapLength2 ]}
755
- diffs = append (
756
- diffs [:pointer ],
757
- append ([]Diff {overlap }, diffs [pointer :]... )... )
758
-
753
+ diffs = splice (diffs , pointer , 0 , overlap )
759
754
diffs [pointer - 1 ].Type = DiffInsert
760
755
diffs [pointer - 1 ].Text = insertion [0 : len (insertion )- overlapLength2 ]
761
756
diffs [pointer + 1 ].Type = DiffDelete
@@ -968,8 +963,7 @@ func (dmp *DiffMatchPatch) DiffCleanupEfficiency(diffs []Diff) []Diff {
968
963
insPoint := equalities .data
969
964
970
965
// Duplicate record.
971
- diffs = append (diffs [:insPoint ],
972
- append ([]Diff {Diff {DiffDelete , lastequality }}, diffs [insPoint :]... )... )
966
+ diffs = splice (diffs , insPoint , 0 , Diff {DiffDelete , lastequality })
973
967
974
968
// Change second copy to insert.
975
969
diffs [insPoint + 1 ].Type = DiffInsert
0 commit comments