OSDN Git Service

Usage std::move(), replace ' = ""; ' to '.clear()' and remove unused vars
authorgermanaizek <GermanAizek@yandex.ru>
Fri, 18 Mar 2022 16:05:57 +0000 (19:05 +0300)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Fri, 18 Mar 2022 23:42:23 +0000 (08:42 +0900)
25 files changed:
Src/7zCommon.cpp
Src/Common/RegOptionsMgr.cpp
Src/Common/ShellContextMenu.cpp
Src/Common/multiformatText.cpp
Src/DiffTextBuffer.cpp
Src/DiffWrapper.cpp
Src/DirActions.cpp
Src/DirCmpReport.cpp
Src/DirView.cpp
Src/DirViewColItems.cpp
Src/FileFilterMgr.cpp
Src/ImgMergeFrm.cpp
Src/InternalPlugins.cpp
Src/LocationView.cpp
Src/Merge.cpp
Src/MergeDoc.cpp
Src/MergeFrameCommon.cpp
Src/OpenView.cpp
Src/OptionsEditorSyntax.cpp
Src/PatchDlg.cpp
Src/PatchTool.cpp
Src/Plugins.cpp
Src/SelectPluginDlg.cpp
Src/TempFile.cpp
Src/paths.cpp

index 0335c4c..a202b85 100644 (file)
@@ -706,7 +706,8 @@ DecompressResult DecompressArchive(HWND hWnd, const PathContext& files)
                        if (!PathFileExists(res.files[0].c_str()) || !PathFileExists(res.files[1].c_str()))\r
                        {\r
                                // not a Perry style patch: diff with itself...\r
-                               res.files[0] = res.files[1] = path;\r
+                               res.files[0] = path;\r
+                               res.files[1] = std::move(path);\r
                        }\r
                        else\r
                        {\r
index 7bd2bc7..745fbb4 100644 (file)
@@ -523,7 +523,7 @@ int CRegOptionsMgr::SetRegRootKey(const String& key)
        if (ind != 0)
                keyname.insert(0, _T("Software\\"));
        
-       m_registryRoot = keyname;
+       m_registryRoot = std::move(keyname);
 
        LONG retValReg =  RegCreateKeyEx(HKEY_CURRENT_USER, m_registryRoot.c_str(), 0, nullptr,
                REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, nullptr, &hKey, &action);
index 8428731..bf1ee90 100644 (file)
@@ -209,8 +209,8 @@ bool CShellContextMenu::QueryShellContextMenu()
                return false;
        }
 
-       m_pShellContextMenu2 = pCMenu2;
-       m_pShellContextMenu3 = pCMenu3;
+       m_pShellContextMenu2 = std::move(pCMenu2);
+       m_pShellContextMenu3 = std::move(pCMenu3);
 
        return true;
 }
index b474f41..30c3350 100644 (file)
@@ -100,7 +100,7 @@ const TCHAR *storageForPlugins::GetDestFileName()
                        try
                        {
                                TFile(m_tempFilenameDst).renameTo(tempFilenameDstNew);
-                               m_tempFilenameDst = tempFilenameDstNew;
+                               m_tempFilenameDst = std::move(tempFilenameDstNew);
                        }
                        catch (Exception& e)
                        {
index e5d14fa..0759d26 100644 (file)
@@ -490,7 +490,7 @@ int CDiffTextBuffer::SaveToFile (const String& pszFileName,
                        sLine.append(GetLineChars(line), nLineLength);
                }
                else
-                       sLine = _T("");
+                       sLine.clear();
 
                if (bTempFile && m_bTableEditing && m_bAllowNewlinesInQuotes)
                {
index e8d9c56..0b5a71c 100644 (file)
@@ -1474,7 +1474,7 @@ const SubstitutionList* CDiffWrapper::GetSubstitutionList() const
 
 void CDiffWrapper::SetSubstitutionList(std::shared_ptr<SubstitutionList> pSubstitutionList)
 {
-       m_pSubstitutionList = pSubstitutionList;
+       m_pSubstitutionList = std::move(pSubstitutionList);
 }
 
 void CDiffWrapper::SetFilterCommentsSourceDef(const String& ext)
index 97639b9..1d18047 100644 (file)
@@ -143,10 +143,10 @@ static void ThrowConfirmationNeededException(const CDiffContext& ctxt, const Str
                strDest = paths::AddTrailingSlash(dest);
 
        exp.m_question = question;
-       exp.m_fromText = sOrig;
-       exp.m_toText = sDest;
-       exp.m_fromPath = strSrc;
-       exp.m_toPath = strDest;
+       exp.m_fromText = std::move(sOrig);
+       exp.m_toText = std::move(sDest);
+       exp.m_fromPath = std::move(strSrc);
+       exp.m_toPath = std::move(strDest);
 
        throw exp;
 }
index 2fcc089..412bfbf 100644 (file)
@@ -471,7 +471,7 @@ void DirCmpReport::GenerateXmlHtmlContent(bool xml)
 {
        String sFileName, sParentDir;
        paths::SplitFilename((const TCHAR *)m_pFile->GetFilePath(), &sParentDir, &sFileName, nullptr);
-       String sRelDestDir = sFileName.substr(0, sFileName.find_last_of(_T("."))) + _T(".files");
+       String sRelDestDir = sFileName.substr(0, sFileName.find_last_of(_T('.'))) + _T(".files");
        String sDestDir = paths::ConcatPath(sParentDir, sRelDestDir);
        if (!xml && m_bIncludeFileCmpReport && m_pFileCmpReport != nullptr)
                paths::CreateIfNeeded(sDestDir);
index f91113b..56631a4 100644 (file)
@@ -957,7 +957,7 @@ void CDirView::DoDirActionTo(SIDE_TYPE stype, DirActions::method_type func, cons
        try {
                // First we build a list of desired actions
                FileActionScript actionScript;
-               actionScript.m_destBase = destPath;
+               actionScript.m_destBase = std::move(destPath);
                DirItemWithIndexIterator begin(m_pIList.get(), -1, true);
                DirItemWithIndexIterator end;
                FileActionScript *rsltScript;
@@ -3112,7 +3112,7 @@ void CDirView::OnPluginSettings(UINT nID)
        {
        case ID_PREDIFFER_SETTINGS_NONE:
        case ID_UNPACKER_SETTINGS_NONE:
-               pluginPipeline = _T("");
+               pluginPipeline.clear();
                break;
        case ID_PREDIFFER_SETTINGS_AUTO:
        case ID_UNPACKER_SETTINGS_AUTO:
index dcf701b..6e6ed33 100644 (file)
@@ -423,7 +423,7 @@ static String ColDiffsGet(const CDiffContext *, const void *p, int)
        }
        else if (r == CDiffContext::DIFFS_UNKNOWN)
        { // Unique item
-               s = _T("");
+               s.clear();
        }
        else
        {
index 3c3054b..81a1df6 100644 (file)
@@ -175,7 +175,7 @@ FileFilter * FileFilterMgr::LoadFilterFile(const String& szFilepath, int & error
        paths::SplitFilename(szFilepath, nullptr, &fileName, nullptr);
        FileFilter *pfilter = new FileFilter;
        pfilter->fullpath = szFilepath;
-       pfilter->name = fileName; // Filename is the default name
+       pfilter->name = std::move(fileName); // Filename is the default name
 
        String sLine;
        bool lossy = false;
@@ -185,7 +185,7 @@ FileFilter * FileFilterMgr::LoadFilterFile(const String& szFilepath, int & error
                // Returns false when last line is read
                String tmpLine;
                bLinesLeft = file.ReadString(tmpLine, &lossy);
-               sLine = tmpLine;
+               sLine = std::move(tmpLine);
                sLine = strutils::trim_ws(sLine);
 
                if (0 == sLine.compare(0, 5, _T("name:"), 5))
@@ -194,7 +194,7 @@ FileFilter * FileFilterMgr::LoadFilterFile(const String& szFilepath, int & error
                        String str = sLine.substr(5);
                        str = strutils::trim_ws_begin(str);
                        if (!str.empty())
-                               pfilter->name = str;
+                               pfilter->name = std::move(str);
                }
                else if (0 == sLine.compare(0, 5, _T("desc:"), 5))
                {
@@ -202,7 +202,7 @@ FileFilter * FileFilterMgr::LoadFilterFile(const String& szFilepath, int & error
                        String str = sLine.substr(5);
                        str = strutils::trim_ws_begin(str);
                        if (!str.empty())
-                               pfilter->description = str;
+                               pfilter->description = std::move(str);
                }
                else if (0 == sLine.compare(0, 4, _T("def:"), 4))
                {
index 6e7acd5..9ade692 100644 (file)
@@ -285,7 +285,7 @@ void CImgMergeFrame::ChangeFile(int nBuffer, const String& path)
 
        m_filePaths[nBuffer] = path;
        m_nBufferType[nBuffer] = BUFFERTYPE::NORMAL;
-       m_strDesc[nBuffer] = _T("");
+       m_strDesc[nBuffer].clear();
        int nActivePane = m_pImgMergeWindow->GetActivePane();
 
        OpenImages();
index 8a50853..8dada8d 100644 (file)
@@ -173,7 +173,7 @@ public:
                                        else if (localName == ExtendedPropertiesElement)
                                                plugin.m_extendedProperties = value;
                                        else if (localName == ArgumentsElement)
-                                               plugin.m_arguments = value;
+                                               plugin.m_arguments = std::move(value);
                                }
                                else if (localName == PrediffFileElement)
                                {
index 174d38a..aecdde5 100644 (file)
@@ -548,7 +548,6 @@ void CLocationView::DrawRect(CDC* pDC, const CRect& r, COLORREF cr, bool bSelect
        // Draw only colored blocks
        if (cr != CLR_NONE && cr != GetSysColor(COLOR_WINDOW))
        {
-               CBrush brush(cr);
                CRect drawRect(r);
                drawRect.DeflateRect(1, 0);
 
index 5bb8cb2..c0b1268 100644 (file)
@@ -999,7 +999,7 @@ bool CMergeApp::CreateBackup(bool bFolder, const String& pszPath)
                        PropBackups::FOLDER_ORIGINAL)
                {
                        // Put backups to same folder than original file
-                       bakPath = path;
+                       bakPath = std::move(path);
                }
                else if (GetOptionsMgr()->GetInt(OPT_BACKUP_LOCATION) ==
                        PropBackups::FOLDER_GLOBAL)
@@ -1007,7 +1007,7 @@ bool CMergeApp::CreateBackup(bool bFolder, const String& pszPath)
                        // Put backups to global folder defined in options
                        bakPath = GetOptionsMgr()->GetString(OPT_BACKUP_GLOBALFOLDER);
                        if (bakPath.empty())
-                               bakPath = path;
+                               bakPath = std::move(path);
                        else
                                bakPath = paths::GetLongPath(bakPath);
                }
@@ -1093,7 +1093,6 @@ int CMergeApp::HandleReadonlySave(String& strSavePath, bool bMultiFile,
        bool bFileExists = false;
        String s;
        String str;
-       CString title;
 
        if (!strSavePath.empty())
        {
index f2f9931..2d1972b 100644 (file)
@@ -1626,7 +1626,7 @@ bool CMergeDoc::TrySaveAs(String &strPath, int &nSaveResult, String & sError,
                if (SelectFile(GetActiveMergeView()->GetSafeHwnd(), s, false, strPath.c_str(), title))
                {
                        CDiffTextBuffer *pBuffer = m_ptBuf[nBuffer].get();
-                       strSavePath = s;
+                       strSavePath = std::move(s);
                        nSaveResult = pBuffer->SaveToFile(strSavePath, false, sError,
                                infoTempUnpacker);
 
@@ -1774,9 +1774,9 @@ bool CMergeDoc::DoSave(LPCTSTR szPath, bool &bSaveSuccess, int nBuffer)
                }
 
                m_ptBuf[nBuffer]->SetModified(false);
-               m_pSaveFileInfo[nBuffer]->Update(strSavePath.c_str());
-               m_filePaths[nBuffer] = strSavePath;
-               m_pRescanFileInfo[nBuffer]->Update(m_filePaths[nBuffer].c_str());
+               m_pSaveFileInfo[nBuffer]->Update(strSavePath);
+               m_filePaths[nBuffer] = std::move(strSavePath);
+               m_pRescanFileInfo[nBuffer]->Update(m_filePaths[nBuffer]);
                UpdateHeaderPath(nBuffer);
                bSaveSuccess = true;
                result = true;
@@ -1837,7 +1837,7 @@ bool CMergeDoc::DoSaveAs(LPCTSTR szPath, bool &bSaveSuccess, int nBuffer)
        if (nSaveErrorCode == SAVE_DONE)
        {
                m_pSaveFileInfo[nBuffer]->Update(strSavePath);
-               m_filePaths[nBuffer] = strSavePath;
+               m_filePaths[nBuffer] = std::move(strSavePath);
                m_pRescanFileInfo[nBuffer]->Update(m_filePaths[nBuffer]);
                UpdateHeaderPath(nBuffer);
                bSaveSuccess = true;
@@ -3374,7 +3374,7 @@ void CMergeDoc::ChangeFile(int nBuffer, const String& path, int nLineIndex)
        }
        std::copy_n(m_strDesc, m_nBuffers, strDesc);
 
-       strDesc[nBuffer] = _T("");
+       strDesc[nBuffer].clear();
        fileloc[nBuffer].setPath(path);
        fileloc[nBuffer].encoding = codepage_detect::Guess(path, GetOptionsMgr()->GetInt(OPT_CP_DETECT));
 
index 6bef940..24943ea 100644 (file)
@@ -195,7 +195,6 @@ String CMergeFrameCommon::GetTooltipString(const PathContext& paths, const Strin
                        sTitle += _("Right");\r
                sTitle += _T("\n");\r
        }\r
-       String flags;\r
        if (pInfoUnpacker && !pInfoUnpacker->GetPluginPipeline().empty())\r
                sTitle += strutils::format(_T("%s: %s\n"), _("Unpacker"), pInfoUnpacker->GetPluginPipeline());\r
        if (pInfoPrediffer && !pInfoPrediffer->GetPluginPipeline().empty())\r
index 9858b31..032c0f5 100644 (file)
@@ -564,7 +564,7 @@ void COpenView::OnPathButton(UINT nId)
        if (SelectFileOrFolder(GetSafeHwnd(), s, sfolder.c_str()))
        {
                m_strPath[index] = s;
-               m_strBrowsePath[index] = s;
+               m_strBrowsePath[index] = std::move(s);
                UpdateData(FALSE);
                UpdateButtonStates();
        }       
@@ -807,7 +807,7 @@ void COpenView::OnLoadProject()
        {
                m_strPath[0] = paths[0];
                m_strPath[1] = paths[1];
-               m_strPath[2] = _T("");
+               m_strPath[2].clear();
                m_bReadOnly[0] = projItem.GetLeftReadOnly();
                m_bReadOnly[1] = projItem.GetRightReadOnly();
                m_bReadOnly[2] = false;
@@ -936,7 +936,7 @@ void COpenView::OnSaveProject()
 
 void COpenView::DropDown(NMHDR* pNMHDR, LRESULT* pResult, UINT nID, UINT nPopupID)
 {
-       CRect rcButton, rcView;
+       CRect rcButton;
        GetDlgItem(nID)->GetWindowRect(&rcButton);
        BCMenu menu;
        VERIFY(menu.LoadMenu(nPopupID));
index c38b8ac..acd0038 100644 (file)
@@ -26,7 +26,7 @@ void GetDefaults(COptionsMgr* pOptionsMgr, String* pExtension)
                {
                        String name = strutils::format(_T("%s/%s.exts"), Section, def->name);
                        String exts = pOptionsMgr->GetDefault<String>(name);
-                       pExtension[i-1] = exts;
+                       pExtension[i-1] = std::move(exts);
                }
        }
 }
@@ -75,7 +75,7 @@ void Load(COptionsMgr *pOptionsMgr, String* pExtension)
                {
                        String name = strutils::format(_T("%s/%s.exts"), Section, def->name);
                        String exts = pOptionsMgr->GetString(name);
-                       pExtension[i-1] = exts;
+                       pExtension[i-1] = std::move(exts);
                }
        }
 }
index 503aeaa..76ccc7b 100644 (file)
@@ -118,9 +118,9 @@ void CPatchDlg::OnOK()
 
                PATCHFILES tFiles = m_fileList[0];
                if (tFiles.lfile != m_file1 && !tFiles.pathLeft.empty())
-                       tFiles.pathLeft = _T("");
+                       tFiles.pathLeft.clear();
                if (tFiles.rfile != m_file2 && !tFiles.pathRight.empty())
-                       tFiles.pathRight = _T("");
+                       tFiles.pathRight.clear();
                tFiles.lfile = m_file1;
                tFiles.rfile = m_file2;
                m_fileList[0] = tFiles;
index 711c22a..dba1bfc 100644 (file)
@@ -281,7 +281,7 @@ void CPatchTool::AddFilesToList(const String& sDir1, const String& sDir2, const
                if (!sDir1.empty())
                        pathLeft = sDir1 + backslash;
                pathLeft += ent1->filename.get();
-               tFiles.pathLeft = pathLeft;
+               tFiles.pathLeft = std::move(pathLeft);
        }
 
        if (ent2 != nullptr)
@@ -293,7 +293,7 @@ void CPatchTool::AddFilesToList(const String& sDir1, const String& sDir2, const
                        pathRight = sDir2 + backslash;
                pathRight += ent2->filename.get();
 
-               tFiles.pathRight = pathRight;
+               tFiles.pathRight = std::move(pathRight);
        }
 
        fileList->push_back(tFiles);
index e9c030d..168af96 100644 (file)
@@ -749,7 +749,7 @@ static void ResolveNameConflict(std::map<std::wstring, PluginArrayPtr> plugins)
                                                                String nameNew = name + strutils::format(_T("(%d)"), i + 2);
                                                                if (pluginNames.find(nameNew) == pluginNames.end())
                                                                {
-                                                                       name = nameNew;
+                                                                       name = std::move(nameNew);
                                                                        break;
                                                                }
                                                        }
index 4cbde2e..9455a21 100644 (file)
@@ -30,9 +30,9 @@ void CSelectPluginDlg::Initialize(PluginType pluginType)
        //{{AFX_DATA_INIT(CSelectPluginDlg)
        m_bNoExtensionCheck = false;
        m_bOpenInSameFrameType = false;
-       m_strDescription = _T("");
-       m_strExtensions = _T("");
-       m_strArguments = _T("");
+       m_strDescription.clear();
+       m_strExtensions.clear();
+       m_strArguments.clear();
        //}}AFX_DATA_INIT
 
        // texts for the default unpackers
index 6fe346c..64d0ae9 100644 (file)
@@ -50,7 +50,7 @@ String TempFile::Create(const String& prefix, const String& ext)
                {
                        String tempext = temp + ext;
                        if (MoveFile(temp.c_str(), tempext.c_str()))
-                               temp = tempext;
+                               temp = std::move(tempext);
                }
                m_path = temp;
        }
@@ -68,7 +68,7 @@ bool TempFile::Delete()
        if (!m_path.empty())
                success = !!DeleteFile(m_path.c_str());
        if (success)
-               m_path = _T("");
+               m_path.clear();
        return success;
 }
 /** 
index a022245..be38751 100644 (file)
@@ -286,7 +286,7 @@ String GetLongPath(const String& szPath, bool bExpandEnvs)
                HANDLE h = FindFirstFile(TFile(sTemp).wpath().c_str(), &ffd);
                if (h == INVALID_HANDLE_VALUE)
                {
-                       sLong = sTemp;
+                       sLong = std::move(sTemp);
                        if (ptr != nullptr)
                        {
                                sLong += '\\';