OSDN Git Service

Improve 'Match similar lines' (related to the issue #1013 Vertical shifting needed...
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sat, 6 Nov 2021 01:26:35 +0000 (10:26 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sat, 6 Nov 2021 01:26:35 +0000 (10:26 +0900)
- Reduce the execution time of the GetMatchCost() function
- Remove the 15-line limit for a single Diff block, and instead make the limit to 4096 characters per Diff block

Src/MergeDocDiffSync.cpp

index 1a26e25..445cc74 100644 (file)
@@ -153,12 +153,12 @@ int CMergeDoc::GetMatchCost(int line0, int line1, const std::vector<WordDiff>& w
                                        matchlen += worddiffs[i].begin[0];
                        }
                }
-       }
-       if (!worddiffs.empty())
-       {
-               size_t last = worddiffs.size() - 1;
-               if (worddiffs[last].endline[0] == line0 && worddiffs[last].endline[1] == line1)
-                       matchlen += m_ptBuf[0]->GetFullLineLength(line0) - worddiffs[last].end[0] - 1;
+               if (i == worddiffs.size() - 1 ||
+                       worddiffs[i + 1].beginline[0] != worddiffs[i].endline[0] && worddiffs[i + 1].beginline[1] != worddiffs[i].endline[1])
+               {
+                       if (worddiffs[i].endline[0] == line0 && worddiffs[i].endline[1] == line1)
+                               matchlen += m_ptBuf[0]->GetFullLineLength(line0) - worddiffs[i].end[0] - 1;
+               }
        }
        return -matchlen;
 }