mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2025-01-23 01:36:57 -08:00
optimize<TextCompare>: combine two modified parts those have one same unchanged character
This commit is contained in:
parent
cc326495a6
commit
ade45732f2
1 changed files with 20 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace SourceGit.Models {
|
namespace SourceGit.Models {
|
||||||
|
|
||||||
|
@ -84,6 +84,7 @@ namespace SourceGit.Models {
|
||||||
var ret = new List<Different>();
|
var ret = new List<Different>();
|
||||||
var posOld = 0;
|
var posOld = 0;
|
||||||
var posNew = 0;
|
var posNew = 0;
|
||||||
|
var last = null as Different;
|
||||||
do {
|
do {
|
||||||
while (posOld < sizeOld && posNew < sizeNew && !chunksOld[posOld].Modified && !chunksNew[posNew].Modified) {
|
while (posOld < sizeOld && posNew < sizeNew && !chunksOld[posOld].Modified && !chunksNew[posNew].Modified) {
|
||||||
posOld++;
|
posOld++;
|
||||||
|
@ -97,13 +98,25 @@ namespace SourceGit.Models {
|
||||||
for (; posOld < sizeOld && chunksOld[posOld].Modified; posOld++) countOld += chunksOld[posOld].Size;
|
for (; posOld < sizeOld && chunksOld[posOld].Modified; posOld++) countOld += chunksOld[posOld].Size;
|
||||||
for (; posNew < sizeNew && chunksNew[posNew].Modified; posNew++) countNew += chunksNew[posNew].Size;
|
for (; posNew < sizeNew && chunksNew[posNew].Modified; posNew++) countNew += chunksNew[posNew].Size;
|
||||||
|
|
||||||
if (countOld + countNew > 0) {
|
if (countOld + countNew == 0) continue;
|
||||||
ret.Add(new Different(
|
|
||||||
|
var diff = new Different(
|
||||||
countOld > 0 ? chunksOld[beginOld].Start : 0,
|
countOld > 0 ? chunksOld[beginOld].Start : 0,
|
||||||
countOld,
|
countOld,
|
||||||
countNew > 0 ? chunksNew[beginNew].Start : 0,
|
countNew > 0 ? chunksNew[beginNew].Start : 0,
|
||||||
countNew));
|
countNew);
|
||||||
|
if (last != null) {
|
||||||
|
var midSizeOld = diff.DeletedStart - last.DeletedStart - last.DeletedCount;
|
||||||
|
var midSizeNew = diff.AddedStart - last.AddedStart - last.AddedCount;
|
||||||
|
if (midSizeOld == 1 && midSizeNew == 1) {
|
||||||
|
last.DeletedCount += (1 + countOld);
|
||||||
|
last.AddedCount += (1 + countNew);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
last = diff;
|
||||||
|
ret.Add(diff);
|
||||||
} while (posOld < sizeOld && posNew < sizeNew);
|
} while (posOld < sizeOld && posNew < sizeNew);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in a new issue