OSDN Git Service

Replace std containers, code refactor and minor fixes
authorgermanaizek <GermanAizek@yandex.ru>
Fri, 18 Mar 2022 16:09:50 +0000 (19:09 +0300)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Fri, 18 Mar 2022 23:42:23 +0000 (08:42 +0900)
15 files changed:
ShellExtension/Common/WinMergeContextMenu.cpp
Src/Common/BCMenu.cpp
Src/Common/MDITabBar.cpp
Src/Common/SuperComboBox.cpp
Src/Common/lwdisp.c
Src/ConfigLog.cpp
Src/FileFiltersDlg.cpp
Src/GhostTextView.cpp
Src/MainFrm.cpp
Src/MainFrm.h
Src/MergeCmdLineInfo.cpp
Src/MergeEditView.cpp
Src/SelectPluginDlg.cpp
Src/SubeditList.cpp
Src/paths.cpp

index 05a3975..a0603fd 100644 (file)
@@ -174,6 +174,7 @@ bool WinMergeContextMenu::UpdateMenuState(const std::vector<std::wstring>& paths
 std::vector<MenuItem> WinMergeContextMenu::GetMenuItemList() const
 {
        std::vector<MenuItem> list;
+       list.reserve(3);
        bool isdir = m_strPaths.empty() ? false : !!PathIsDirectory(m_strPaths[0].c_str());
        bool enabled = (m_strPaths.size() <= MaxFileCount);
        int icon = isdir ? IDI_WINMERGEDIR : IDI_WINMERGE;
index 852da25..78d2717 100644 (file)
@@ -1713,7 +1713,7 @@ bool BCMenu::DeleteMenu(UINT uiId,UINT nFlags)
                        INT_PTR menulistsize=m_MenuList.GetSize();      
                        if(uiId<(UINT)menulistsize){
                                CString str=m_MenuList[uiId]->GetString();
-                               if(str==""){
+                               if(str.IsEmpty()){
                                        delete m_MenuList.GetAt(uiId);
                                        m_MenuList.RemoveAt(uiId);
                                }
index ed3732e..e42135f 100644 (file)
@@ -605,7 +605,7 @@ void CMDITabBar::UpdateToolTips(int nTabItemIndex)
                        strTooltip = pITabBar ? pITabBar->GetTooltipString() : _T("");
 
                        if (strTooltip == strTitle && strTitle.GetLength() <= GetMaxTitleLength())
-                               strTooltip = "";
+                               strTooltip.Empty();
 
                        m_tooltips.UpdateTipText(strTooltip, this);
                        CRect rc;
index 9fcef27..db6751e 100644 (file)
@@ -460,7 +460,7 @@ void CSuperComboBox::ResetContent()
                m_sFullStateText.resize(m_nMaxItems);
                for (int i = 0; i < m_nMaxItems; i++)
                {
-                       m_sFullStateText[i] = _T("");
+                       m_sFullStateText[i].Empty();
                }
        }
        CComboBoxEx::ResetContent();
index df1776e..3c2e35e 100644 (file)
@@ -310,7 +310,8 @@ LPDISPATCH NTAPI CreateDispatchBySource(LPCTSTR source, LPCWSTR progid)
                        mycpyt2w(_T("script:"), wc, DIMOF(wc));
                else
                        mycpyt2w(_T(""), wc, DIMOF(wc));
-               mycpyt2w(source, wc+wcslen(wc), DIMOF(wc)-wcslen(wc));
+               size_t len = wcslen(wc);
+               mycpyt2w(source, wc + len, DIMOF(wc) - len);
 
                // I observed that CoGetObject() may internally provoke an access
                // violation and succeed anyway. No idea how to avoid this.
index b748367..5930951 100644 (file)
@@ -305,7 +305,7 @@ bool CConfigLog::DoFile(String &sError)
        text = GetWindowsVer();
        FileWriteString(text);
        text = GetProcessorInfo();
-       if (text != _T(""))
+       if (!text.empty())
        {               
                FileWriteString(_T("\r\n Processor:           "));
                FileWriteString(text);
@@ -445,12 +445,12 @@ String CConfigLog::GetProcessorInfo()
        String sProductName = _T("");
        if (key.QueryRegMachine(_T("Hardware\\Description\\System\\CentralProcessor\\0")))
                sProductName = key.ReadString(_T("Identifier"), _T(""));
-       if (sProductName != _T(""))
+       if (!sProductName.empty())
        {
                // This is the full identifier of the processor
                //      (e.g. "Intel64 Family 6 Model 158 Stepping 9")
                //      but we'll only keep the first word (e.g. "Intel64")
-               int x = (int)sProductName.find_first_of(_T(" "));
+               int x = (int)sProductName.find_first_of(_T(' '));
                sProductName = sProductName.substr(0, x);
        }
 
index d4fd55f..2b91227 100644 (file)
@@ -440,7 +440,7 @@ void FileFiltersDlg::OnBnClickedFilterfileNewbutton()
                TCHAR dir[_MAX_DIR] = {0};
                TCHAR drive[_MAX_DRIVE] = {0};
                _tsplitpath_s(s.c_str(), drive, _MAX_DRIVE, dir, _MAX_DIR, file, _MAX_FNAME, ext, _MAX_EXT);
-               if (_tcslen(ext) == 0)
+               if (ext[0] == '\0')
                {
                        s += FileFilterExt;
                }
index d16f183..9a2e111 100644 (file)
@@ -211,14 +211,14 @@ void CGhostTextView::GetTextWithoutEmptys (int nStartLine, int nStartChar,
   if (m_pGhostTextBuffer != nullptr)
     m_pGhostTextBuffer->GetTextWithoutEmptys (nStartLine, nStartChar, nEndLine, nEndChar, text, nCrlfStyle, bExcludeInvisibleLines);
   else
-    text = _T ("");
+    text.Empty();
 }
 
 void CGhostTextView::GetTextWithoutEmptysInColumnSelection (CString & text, bool bExcludeInvisibleLines /*= true*/)
 {
        if (m_pGhostTextBuffer == nullptr)
        {
-               text = _T ("");
+               text.Empty();
                return;
        }
 
index 3587116..f9eeab3 100644 (file)
@@ -1628,9 +1628,9 @@ HexMergeDocList &CMainFrame::GetAllHexMergeDocs()
        return static_cast<HexMergeDocList &>(GetDocList(theApp.m_pHexMergeTemplate));
 }
 
-std::list<CImgMergeFrame *> CMainFrame::GetAllImgMergeFrames()
+std::vector<CImgMergeFrame *> CMainFrame::GetAllImgMergeFrames()
 {
-       std::list<CImgMergeFrame *> list;
+       std::vector<CImgMergeFrame *> list;
        // Close Non-Document/View frame with confirmation
        CMDIChildWnd *pChild = static_cast<CMDIChildWnd *>(CWnd::FromHandle(m_hWndMDIClient)->GetWindow(GW_CHILD));
        while (pChild != nullptr)
@@ -3141,7 +3141,7 @@ void CMainFrame::AppendPluginMenus(CMenu *pMenu, const String& filteredFilenames
                pMenu->AppendMenu(MF_STRING, ID_NOT_SUGGESTED_PLUGINS, _("All plugins").c_str());
        }
 
-       std::vector<String> processTypes;
+       std::list<String> processTypes;
        for (const auto& [processType, pluginList] : allPlugins)
                processTypes.push_back(processType);
        auto it = std::find(processTypes.begin(), processTypes.end(), _("&Others"));
@@ -3151,7 +3151,7 @@ void CMainFrame::AppendPluginMenus(CMenu *pMenu, const String& filteredFilenames
                processTypes.push_back(_("&Others"));
        }
 
-       for (const auto& processType: processTypes)
+       for (const auto& processType : processTypes)
        {
                CMenu popup;
                popup.CreatePopupMenu();
index e4e4c23..a036bb4 100644 (file)
@@ -384,7 +384,7 @@ private:
        MergeDocList &GetAllMergeDocs();
        DirDocList &GetAllDirDocs();
        HexMergeDocList &GetAllHexMergeDocs();
-       std::list<CImgMergeFrame *> GetAllImgMergeFrames();
+       std::vector<CImgMergeFrame *> GetAllImgMergeFrames();
        void UpdateFont(FRAMETYPE frame);
        BOOL CreateToolbar();
        CMergeEditView * GetActiveMergeEditView();
index 464f283..152622b 100644 (file)
@@ -250,7 +250,7 @@ void MergeCmdLineInfo::ParseWinMergeCmdLine(const TCHAR *q)
                        else if (param == _T("image"))
                                m_nWindowType = WindowType::IMAGE;
                        else
-                               m_sErrorMessages.push_back(_T("Unknown window type '") + param + _T("' specified"));
+                               m_sErrorMessages.emplace_back(_T("Unknown window type '") + param + _T("' specified"));
                }
                else if (param == _T("m"))
                {
@@ -274,7 +274,7 @@ void MergeCmdLineInfo::ParseWinMergeCmdLine(const TCHAR *q)
                        else if (param == _T("size"))
                                m_nCompMethod = CompareMethodType::SIZE;
                        else
-                               m_sErrorMessages.push_back(_T("Unknown compare method '") + param + _T("' specified"));
+                               m_sErrorMessages.emplace_back(_T("Unknown compare method '") + param + _T("' specified"));
                }
                else if (param == _T("r"))
                {
@@ -527,7 +527,7 @@ void MergeCmdLineInfo::ParseWinMergeCmdLine(const TCHAR *q)
                }
                else
                {
-                       m_sErrorMessages.push_back(_T("Unknown option '/") + param + _T("'"));
+                       m_sErrorMessages.emplace_back(_T("Unknown option '/") + param + _T("'"));
                }
        }
        // If "compare file dir" make it "compare file dir\file".
index 2138f0a..df6a080 100644 (file)
@@ -578,7 +578,7 @@ std::map<int, std::vector<int>> CMergeEditView::GetColumnSelectedWordDiffIndice(
                        {
                                std::vector<int> *pWordDiffs;
                                if (list.find(firstDiff) == list.end())
-                                       list.insert(std::pair<int, std::vector<int> *>(firstDiff, new std::vector<int>()));
+                                       list.emplace(firstDiff, new std::vector<int>());
                                pWordDiffs = list[firstDiff];
                                for (int i = firstWordDiff; i <= lastWordDiff; ++i)
                                {
@@ -589,7 +589,7 @@ std::map<int, std::vector<int>> CMergeEditView::GetColumnSelectedWordDiffIndice(
                }
        }
        for (auto& it : list)
-               ret.insert(std::pair<int, std::vector<int>>(it.first, *it.second));
+               ret.emplace(it.first, *it.second);
        return ret;
 }
 
index 9455a21..bc9f0b2 100644 (file)
@@ -164,7 +164,7 @@ void CSelectPluginDlg::prepareListbox()
                m_cboPluginName.AddString(automaticPlugin->m_name.c_str());
        }
 
-       std::vector<String> processTypes;
+       std::list<String> processTypes;
        for (const auto& [processType, pluginList] : m_Plugins)
                processTypes.push_back(processType);
 
index 687c9db..64cefd8 100644 (file)
@@ -153,7 +153,7 @@ void CSubeditList::SetDropListFixedPattern(int nItem, int nSubItem, const String
                return;
 
        for (size_t i = m_dropListFixedPattern.size(); i <= static_cast<size_t>(nItem); i++)
-               m_dropListFixedPattern.push_back(std::vector<String>());
+               m_dropListFixedPattern.emplace_back(std::initializer_list<String>{});
 
        for (size_t i = m_dropListFixedPattern[nItem].size(); i <= static_cast<size_t>(nSubItem); i++)
                m_dropListFixedPattern[nItem].push_back(_T(""));
index be38751..ddca36c 100644 (file)
@@ -464,10 +464,10 @@ bool IsDirectory(const String &path)
  */
 String ExpandShortcut(const String &inFile)
 {
-       assert(inFile != _T(""));
+       assert(!inFile.empty());
 
        // No path, nothing to return
-       if (inFile == _T(""))
+       if (inFile.empty())
                return _T("");
 
        String outFile;