From a644d8c4f151739d0802c08084ab240464fdc91c Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Wed, 3 Aug 2016 23:23:11 +0200 Subject: [PATCH] Optimize variable scopes Signed-off-by: Sven Strickroth --- src/Git/Git.cpp | 8 +++----- src/Git/GitStatusListCtrl.cpp | 5 ++--- src/TGitCache/CacheInterface.cpp | 3 +-- src/TortoiseMerge/BaseView.cpp | 3 +-- src/TortoiseProc/GitDiff.cpp | 5 ++--- src/TortoiseShell/ShellExt.cpp | 12 +++--------- src/Utils/PathUtils.cpp | 6 ++---- 7 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/Git/Git.cpp b/src/Git/Git.cpp index e089eea79..fb4058bfc 100644 --- a/src/Git/Git.cpp +++ b/src/Git/Git.cpp @@ -2292,12 +2292,10 @@ BOOL CGit::CheckCleanWorkTree(bool stagedOk /* false */) } int CGit::Revert(const CString& commit, const CTGitPathList &list, CString& err) { - int ret; for (int i = 0; i < list.GetCount(); ++i) { - ret = Revert(commit, (CTGitPath&)list[i], err); - if(ret) - return ret; + if (Revert(commit, (CTGitPath&)list[i], err)) + return -1; } return 0; } @@ -3392,13 +3390,13 @@ int CGit::GetGitVersion(CString* versiondebug, CString* errStr) return -1; } - int start = 0; int ver = 0; if (versiondebug) *versiondebug = version; try { + int start = 0; CString str = version.Tokenize(_T("."), start); int space = str.ReverseFind(_T(' ')); str = str.Mid(space + 1, start); diff --git a/src/Git/GitStatusListCtrl.cpp b/src/Git/GitStatusListCtrl.cpp index daad7dfbd..5c0d6e36c 100644 --- a/src/Git/GitStatusListCtrl.cpp +++ b/src/Git/GitStatusListCtrl.cpp @@ -2065,15 +2065,14 @@ void CGitStatusListCtrl::OnContextMenuList(CWnd * pWnd, CPoint point) case IDGITLC_COMPARETWOFILES: { POSITION pos = GetFirstSelectedItemPosition(); - CTGitPath* firstfilepath = nullptr, *secondfilepath = nullptr; if (pos) { - firstfilepath = (CTGitPath * )GetItemData(GetNextSelectedItem(pos)); + CTGitPath* firstfilepath = (CTGitPath*)GetItemData(GetNextSelectedItem(pos)); ASSERT(firstfilepath); if (!firstfilepath) break; - secondfilepath = (CTGitPath * )GetItemData(GetNextSelectedItem(pos)); + CTGitPath* secondfilepath = (CTGitPath*)GetItemData(GetNextSelectedItem(pos)); ASSERT(secondfilepath); if (!secondfilepath) break; diff --git a/src/TGitCache/CacheInterface.cpp b/src/TGitCache/CacheInterface.cpp index 6d0361446..bb492bf90 100644 --- a/src/TGitCache/CacheInterface.cpp +++ b/src/TGitCache/CacheInterface.cpp @@ -59,7 +59,6 @@ CString GetCacheID() bool SendCacheCommand(BYTE command, const WCHAR* path /* = nullptr */) { - int retrycount = 2; CAutoFile hPipe; CString pipeName = GetCacheCommandPipeName(); for (int retry = 0; retry < 2; ++retry) @@ -107,7 +106,7 @@ bool SendCacheCommand(BYTE command, const WCHAR* path /* = nullptr */) if (path) _tcsncpy_s(cmd.path, path, _TRUNCATE); - retrycount = 2; + int retrycount = 2; BOOL fSuccess = FALSE; do { diff --git a/src/TortoiseMerge/BaseView.cpp b/src/TortoiseMerge/BaseView.cpp index f9ff9e5f2..24f034059 100644 --- a/src/TortoiseMerge/BaseView.cpp +++ b/src/TortoiseMerge/BaseView.cpp @@ -865,7 +865,6 @@ int CBaseView::GetScreenLines() { CRect rect; GetClientRect(&rect); - int scrollBarHeight = 0; SCROLLBARINFO sbi = { sizeof(sbi) }; if (GetScrollBarInfo(OBJID_HSCROLL, &sbi)) { @@ -874,7 +873,7 @@ int CBaseView::GetScreenLines() // and calculate the screen lines without it. if (!(sbi.rgstate[0] & STATE_SYSTEM_INVISIBLE) && !(sbi.rgstate[0] & STATE_SYSTEM_UNAVAILABLE)) { - scrollBarHeight = sbi.rcScrollBar.bottom - sbi.rcScrollBar.top; + int scrollBarHeight = sbi.rcScrollBar.bottom - sbi.rcScrollBar.top; m_nScreenLines = (rect.Height() - HEADERHEIGHT - scrollBarHeight) / GetLineHeight(); if (m_nScreenLines < 0) m_nScreenLines = 0; diff --git a/src/TortoiseProc/GitDiff.cpp b/src/TortoiseProc/GitDiff.cpp index 6cbec9678..cc245ad04 100644 --- a/src/TortoiseProc/GitDiff.cpp +++ b/src/TortoiseProc/GitDiff.cpp @@ -337,11 +337,10 @@ void CGitDiff::GetSubmoduleChangeType(CGit& subgit, const CString& oldhash, cons } else if (oldhash != newhash) { - bool ffNewer = false, ffOlder = false; - ffNewer = subgit.IsFastForward(oldhash, newhash); + bool ffNewer = subgit.IsFastForward(oldhash, newhash); if (!ffNewer) { - ffOlder = subgit.IsFastForward(newhash, oldhash); + bool ffOlder = subgit.IsFastForward(newhash, oldhash); if (!ffOlder) { if (newTime > oldTime) diff --git a/src/TortoiseShell/ShellExt.cpp b/src/TortoiseShell/ShellExt.cpp index 57dc5b6cb..1e6898235 100644 --- a/src/TortoiseShell/ShellExt.cpp +++ b/src/TortoiseShell/ShellExt.cpp @@ -122,8 +122,6 @@ void LoadLangDll() UINT nFixedLength = 0; LPSTR lpVersion = nullptr; VOID* lpFixedPointer; - TRANSARRAY* lpTransArray; - TCHAR strLangProductVersion[MAX_PATH] = {0}; if (GetFileVersionInfo((LPTSTR)langDll, dwReserved, @@ -136,18 +134,14 @@ void LoadLangDll() &lpFixedPointer, &nFixedLength)) { - lpTransArray = (TRANSARRAY*) lpFixedPointer; + TRANSARRAY* lpTransArray = (TRANSARRAY*)lpFixedPointer; + TCHAR strLangProductVersion[MAX_PATH] = { 0 }; _stprintf_s(strLangProductVersion, _T("\\StringFileInfo\\%04x%04x\\ProductVersion"), lpTransArray[0].wLanguageID, lpTransArray[0].wCharacterSet); - if (VerQueryValue(pBuffer, - (LPTSTR)strLangProductVersion, - (LPVOID *)&lpVersion, - &nInfoSize)) - { + if (VerQueryValue(pBuffer, (LPTSTR)strLangProductVersion, (LPVOID*)&lpVersion, &nInfoSize)) versionmatch = (_tcscmp((LPCTSTR)lpVersion, _T(STRPRODUCTVER)) == 0); - } } } diff --git a/src/Utils/PathUtils.cpp b/src/Utils/PathUtils.cpp index 9568ae60a..b6ef3d1fc 100644 --- a/src/Utils/PathUtils.cpp +++ b/src/Utils/PathUtils.cpp @@ -71,18 +71,16 @@ void CPathUtils::Unescape(char * psz) } char nValue = '?'; - const char* pszLow = nullptr; - const char* pszHigh = nullptr; ++pszSource; *pszSource = (char) toupper(*pszSource); - pszHigh = strchr(szHex, *pszSource); + const char* pszHigh = strchr(szHex, *pszSource); if (pszHigh) { ++pszSource; *pszSource = (char) toupper(*pszSource); - pszLow = strchr(szHex, *pszSource); + const char* pszLow = strchr(szHex, *pszSource); if (pszLow) { -- 2.11.4.GIT