Skip to content

Commit 6d05c43

Browse files
committed
Use only char diffs in change decision logic
1 parent 0f9afd2 commit 6d05c43

1 file changed

Lines changed: 13 additions & 51 deletions

File tree

src/Engine/Engine.cpp

Lines changed: 13 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,15 +1285,6 @@ std::vector<std::set<LinesConv>> getOrderedConvergence(const DocCmpInfo& doc1, c
12851285
const intptr_t linesCount1 = static_cast<intptr_t>(chunk1.size());
12861286
const intptr_t linesCount2 = static_cast<intptr_t>(chunk2.size());
12871287

1288-
std::vector<std::vector<Word>> words2(linesCount2);
1289-
1290-
if (!options.detectCharDiffs)
1291-
{
1292-
for (intptr_t line2 = 0; line2 < linesCount2; ++line2)
1293-
if (!chunk2[line2].empty())
1294-
words2[line2] = getLineWords(doc2.view, doc2.lines[blockDiff2.off + line2].line, options);
1295-
}
1296-
12971288
std::vector<std::set<LinesConv>> lines1Convergence(linesCount1);
12981289
std::vector<std::set<LinesConv>> lines2Convergence(linesCount2);
12991290

@@ -1338,58 +1329,29 @@ std::vector<std::set<LinesConv>> getOrderedConvergence(const DocCmpInfo& doc1, c
13381329
intptr_t matchesCount = 0;
13391330
intptr_t diffsCount = 0;
13401331

1341-
if (!options.detectCharDiffs)
1342-
{
1343-
if (words1.empty())
1344-
words1 = getLineWords(doc1.view, doc1.lines[blockDiff1.off + line1].line, options);
1345-
1346-
auto wordDiffs = DiffCalc<Word>(words1, words2[line2])(true);
1332+
auto charDiffs = DiffCalc<Char>(chunk1[line1], chunk2[line2])();
13471333

1348-
const std::vector<Word>& rWord = wordDiffs.second ? words2[line2] : words1;
1334+
const intptr_t charDiffsSize = static_cast<intptr_t>(charDiffs.first.size());
13491335

1350-
const intptr_t wordDiffsSize = static_cast<intptr_t>(wordDiffs.first.size());
1351-
1352-
for (intptr_t i = 0; i < wordDiffsSize; ++i)
1336+
for (intptr_t i = 0; i < charDiffsSize; ++i)
1337+
{
1338+
if (charDiffs.first[i].type == diff_type::DIFF_MATCH)
13531339
{
1354-
if (wordDiffs.first[i].type == diff_type::DIFF_MATCH)
1355-
{
1356-
matchesCount += (
1357-
rWord[wordDiffs.first[i].off + wordDiffs.first[i].len - 1].pos +
1358-
rWord[wordDiffs.first[i].off + wordDiffs.first[i].len - 1].len -
1359-
rWord[wordDiffs.first[i].off].pos);
1360-
}
1361-
else
1362-
{
1363-
if (options.bestSeqChangedLines)
1364-
++diffsCount;
1365-
1366-
// Count replacement as a single diff
1367-
if ((i + 1 < wordDiffsSize) && (wordDiffs.first[i + 1].type == diff_type::DIFF_IN_2))
1368-
++i;
1369-
}
1340+
matchesCount += charDiffs.first[i].len;
13701341
}
1371-
1372-
if (matchesCount == 0)
1342+
else if (options.bestSeqChangedLines)
13731343
{
1374-
++linesProgress;
1375-
continue;
1376-
}
1377-
}
1378-
else
1379-
{
1380-
auto charDiffs = DiffCalc<Char>(chunk1[line1], chunk2[line2])();
1344+
++diffsCount;
13811345

1382-
for (const auto& ld: charDiffs.first)
1383-
{
1384-
if (ld.type == diff_type::DIFF_MATCH)
1385-
matchesCount += ld.len;
1346+
// Count replacement as a single diff
1347+
if ((i + 1 < charDiffsSize) && (charDiffs.first[i + 1].type == diff_type::DIFF_IN_2))
1348+
++i;
13861349
}
13871350
}
13881351

1389-
if (((matchesCount * 100) / minSize) >= options.changedThresholdPercent)
1352+
if (((matchesCount * 100) / maxSize) >= options.changedThresholdPercent)
13901353
{
1391-
const float lineConvergence = ((static_cast<float>(matchesCount) * 100) / minSize) +
1392-
((static_cast<float>(matchesCount) * 100) / maxSize);
1354+
const float lineConvergence = (static_cast<float>(matchesCount) * 100) / maxSize;
13931355

13941356
Conv conv(lineConvergence, diffsCount);
13951357

0 commit comments

Comments
 (0)