Skip to content

Commit f95ece6

Browse files
committed
Improve performance when there are many differences (3)
1 parent 52dbcf5 commit f95ece6

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/WinWebDiffLib/WebDiffWindow.hpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,27 +1142,31 @@ class CWebDiffWindow : public IWebDiffWindow
11421142
return S_OK;
11431143
}
11441144

1145-
HRESULT applyDOMLoop(std::shared_ptr<std::vector<WDocument>> documents, IWebDiffCallback* callback, int pane = 0)
1145+
HRESULT applyDOMLoop(std::shared_ptr<std::vector<WDocument>> documents, IWebDiffCallback* callback)
11461146
{
11471147
ComPtr<IWebDiffCallback> callback2(callback);
1148-
auto nodes = std::make_shared<std::list<ModifiedNode>>();
1149-
Highlighter::modifiedNodesToHTMLs((*documents)[pane][L"root"], *nodes);
1150-
HRESULT hr = applyHTMLLoop(pane, nodes,
1151-
Callback<IWebDiffCallback>([this, documents, callback2, pane](const WebDiffCallbackResult& result) -> HRESULT
1152-
{
1153-
HRESULT hr = result.errorCode;
1154-
if (SUCCEEDED(hr))
1148+
auto count = std::make_shared<int>();
1149+
for (int pane = 0; pane < m_nPanes; ++pane)
1150+
{
1151+
auto nodes = std::make_shared<std::list<ModifiedNode>>();
1152+
Highlighter::modifiedNodesToHTMLs((*documents)[pane][L"root"], *nodes);
1153+
HRESULT hr = applyHTMLLoop(pane, nodes,
1154+
Callback<IWebDiffCallback>([this, callback2, count](const WebDiffCallbackResult& result) -> HRESULT
11551155
{
1156-
if (pane + 1 < m_nPanes)
1157-
hr = applyDOMLoop(documents, callback2.Get(), pane + 1);
1158-
else if (callback2)
1159-
return callback2->Invoke({ hr, nullptr });
1160-
}
1161-
if (FAILED(hr) && callback2)
1162-
return callback2->Invoke({ hr, nullptr });
1163-
return hr;
1164-
}).Get());
1165-
return hr;
1156+
(*count)++;
1157+
if (*count == m_nPanes && callback2)
1158+
callback2->Invoke({ result.errorCode, nullptr });
1159+
return S_OK;
1160+
}).Get());
1161+
if (FAILED(hr))
1162+
{
1163+
(*count)++;
1164+
if (*count == m_nPanes && callback2)
1165+
callback2->Invoke({ hr, nullptr });
1166+
}
1167+
1168+
}
1169+
return S_OK;
11661170
}
11671171

11681172
HRESULT setStyleSheetLoop(const std::wstring& styles, IWebDiffCallback* callback, int pane = 0)

0 commit comments

Comments
 (0)