From f3b6b83bf893f0d85b48da8102856079d351599c Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Sun, 5 Nov 2017 18:53:10 +0100 Subject: [PATCH] Pass the auto completion map via move semantics to the Scintilla control to avoid creating copies Inspired by TortoiseSVN rev. 26352. Signed-off-by: Sven Strickroth --- src/TortoiseProc/CommitDlg.cpp | 26 +++++++++++++------------- src/TortoiseProc/CommitDlg.h | 5 ++--- src/Utils/MiscUI/SciEdit.cpp | 4 ++-- src/Utils/MiscUI/SciEdit.h | 2 +- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/TortoiseProc/CommitDlg.cpp b/src/TortoiseProc/CommitDlg.cpp index ead827d97..a9bf5b1b4 100644 --- a/src/TortoiseProc/CommitDlg.cpp +++ b/src/TortoiseProc/CommitDlg.cpp @@ -1371,15 +1371,15 @@ UINT CCommitDlg::StatusThread() SetDlgTitle(); - m_autolist.clear(); // we don't have to block the commit dialog while we fetch the // auto completion list. m_pathwatcher.ClearChangedPaths(); InterlockedExchange(&m_bBlock, FALSE); + std::map autolist; if ((DWORD)CRegDWORD(L"Software\\TortoiseGit\\Autocompletion", TRUE) == TRUE) { m_ListCtrl.BusyCursor(true); - GetAutocompletionList(); + GetAutocompletionList(autolist); m_ListCtrl.BusyCursor(false); } SendMessage(WM_UPDATEOKBUTTON); @@ -1432,7 +1432,7 @@ UINT CCommitDlg::StatusThread() UpdateCheckLinks(); // we have the list, now signal the main thread about it - SendMessage(WM_AUTOLISTREADY); // only send the message if the thread wasn't told to quit! + SendMessage(WM_AUTOLISTREADY, 0, (LPARAM)&autolist); // only send the message if the thread wasn't told to quit! } InterlockedExchange(&m_bRunThread, FALSE); @@ -1725,9 +1725,9 @@ LRESULT CCommitDlg::OnFileDropped(WPARAM, LPARAM lParam) return 0; } -LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM) +LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM lparam) { - m_cLogMessage.SetAutoCompletionList(m_autolist, '*'); + m_cLogMessage.SetAutoCompletionList(std::move(*reinterpret_cast*>(lparam)), '*'); return 0; } @@ -1819,7 +1819,7 @@ void CCommitDlg::ParseSnippetFile(const CString& sFile, std::map& autolist) { // the auto completion list is made of strings from each selected files. // the strings used are extracted from the files with regexes found @@ -1852,7 +1852,7 @@ void CCommitDlg::GetAutocompletionList() if (PathFileExists(sSnippetFile)) ParseSnippetFile(sSnippetFile, m_snippet); for (const auto& snip : m_snippet) - m_autolist.emplace(snip.first, AUTOCOMPLETE_SNIPPET); + autolist.emplace(snip.first, AUTOCOMPLETE_SNIPPET); ULONGLONG starttime = GetTickCount64(); @@ -1886,7 +1886,7 @@ void CCommitDlg::GetAutocompletionList() sExt = path->GetFileExtension(); action = path->m_Action; } - m_autolist.emplace(sPartPath, AUTOCOMPLETE_FILENAME); + autolist.emplace(sPartPath, AUTOCOMPLETE_FILENAME); int pos = 0; int lastPos = 0; @@ -1894,7 +1894,7 @@ void CCommitDlg::GetAutocompletionList() { ++pos; lastPos = pos; - m_autolist.emplace(sPartPath.Mid(pos), AUTOCOMPLETE_FILENAME); + autolist.emplace(sPartPath.Mid(pos), AUTOCOMPLETE_FILENAME); } // Last inserted entry is a file name. @@ -1903,7 +1903,7 @@ void CCommitDlg::GetAutocompletionList() { int dotPos = sPartPath.ReverseFind('.'); if ((dotPos >= 0) && (dotPos > lastPos)) - m_autolist.emplace(sPartPath.Mid(lastPos, dotPos - lastPos), AUTOCOMPLETE_FILENAME); + autolist.emplace(sPartPath.Mid(lastPos, dotPos - lastPos), AUTOCOMPLETE_FILENAME); } if (action == CTGitPath::LOGACTIONS_UNVER && !CRegDWORD(L"Software\\TortoiseGit\\AutocompleteParseUnversioned", FALSE)) @@ -1917,12 +1917,12 @@ void CCommitDlg::GetAutocompletionList() if (rdata.IsEmpty()) continue; - ScanFile(sWinPath, rdata, sExt); + ScanFile(autolist, sWinPath, rdata, sExt); } CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Auto completion list loaded in %I64u msec\n", GetTickCount64() - starttime); } -void CCommitDlg::ScanFile(const CString& sFilePath, const CString& sRegex, const CString& sExt) +void CCommitDlg::ScanFile(std::map& autolist, const CString& sFilePath, const CString& sRegex, const CString& sExt) { static std::map regexmap; @@ -2012,7 +2012,7 @@ void CCommitDlg::ScanFile(const CString& sFilePath, const CString& sRegex, const for (size_t i = 1; i < match.size(); ++i) { if (match[i].second-match[i].first) - m_autolist.emplace(std::wstring(match[i]).c_str(), AUTOCOMPLETE_PROGRAMCODE); + autolist.emplace(std::wstring(match[i]).c_str(), AUTOCOMPLETE_PROGRAMCODE); } } } diff --git a/src/TortoiseProc/CommitDlg.h b/src/TortoiseProc/CommitDlg.h index 44c3e7833..cfca49070 100644 --- a/src/TortoiseProc/CommitDlg.h +++ b/src/TortoiseProc/CommitDlg.h @@ -134,8 +134,8 @@ protected: void Refresh(); void StartStatusThread(); void StopStatusThread(); - void GetAutocompletionList(); - void ScanFile(const CString& sFilePath, const CString& sRegex, const CString& sExt); + void GetAutocompletionList(std::map& autolist); + void ScanFile(std::map& autolist, const CString& sFilePath, const CString& sRegex, const CString& sExt); void DoSize(int delta); void SetSplitterRange(); void SaveSplitterPos(); @@ -183,7 +183,6 @@ protected: private: CWinThread* m_pThread; - std::map m_autolist; std::map m_snippet; CGitStatusListCtrl m_ListCtrl; BOOL m_bShowUnversioned; diff --git a/src/Utils/MiscUI/SciEdit.cpp b/src/Utils/MiscUI/SciEdit.cpp index f4af112b4..1aae43220 100644 --- a/src/Utils/MiscUI/SciEdit.cpp +++ b/src/Utils/MiscUI/SciEdit.cpp @@ -465,7 +465,7 @@ void CSciEdit::SetFont(CString sFontName, int iFontSizeInPoints) Call(SCI_SETHOTSPOTACTIVEUNDERLINE, (LPARAM)TRUE); } -void CSciEdit::SetAutoCompletionList(const std::map& list, TCHAR separator, TCHAR typeSeparator) +void CSciEdit::SetAutoCompletionList(std::map&& list, TCHAR separator, TCHAR typeSeparator) { //copy the auto completion list. @@ -473,7 +473,7 @@ void CSciEdit::SetAutoCompletionList(const std::map& list, TCHAR s //to the list and use that instead. But then the caller would have to make //sure that the list persists over the lifetime of the control! m_autolist.clear(); - m_autolist = list; + m_autolist = std::move(list); m_separator = separator; m_typeSeparator = typeSeparator; } diff --git a/src/Utils/MiscUI/SciEdit.h b/src/Utils/MiscUI/SciEdit.h index e4a7f7515..2c5e14c25 100644 --- a/src/Utils/MiscUI/SciEdit.h +++ b/src/Utils/MiscUI/SciEdit.h @@ -119,7 +119,7 @@ public: /** * Adds a list of words for use in auto completion. */ - void SetAutoCompletionList(const std::map& list, TCHAR separator = ';', TCHAR typeSeparator = '?'); + void SetAutoCompletionList(std::map&& list, TCHAR separator = ';', TCHAR typeSeparator = '?'); /** * Returns the word located under the cursor. */ -- 2.11.4.GIT