From 0588b5d8b63d487a9f27212152b511690e461059 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Wed, 3 Aug 2016 16:31:10 +0200 Subject: [PATCH] Avoid creation of intermediates Signed-off-by: Sven Strickroth --- src/Git/Git.cpp | 2 +- src/Git/Git.h | 2 +- src/Git/GitAdminDir.cpp | 6 +++--- src/Git/GitIndex.cpp | 20 ++++++++++---------- src/Git/GitPatch.cpp | 11 ++++++----- src/Git/GitStatus.cpp | 4 ++-- src/Git/TGitPath.cpp | 5 ++--- src/TortoiseProc/AppUtils.cpp | 8 ++++---- src/TortoiseProc/CommitDlg.cpp | 4 ++-- 9 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/Git/Git.cpp b/src/Git/Git.cpp index 3bd87bec8..4b18d97b5 100644 --- a/src/Git/Git.cpp +++ b/src/Git/Git.cpp @@ -1967,7 +1967,7 @@ int CGit::GetMapHashToFriendName(MAP_HASH_NAME &map) return; CGitHash hash; - hash.ConvertFromStrA(lineA.Left(start)); + hash.ConvertFromStrA(lineA); map[hash].push_back(CUnicodeUtils::GetUnicode(lineA.Mid(start + 1))); }); diff --git a/src/Git/Git.h b/src/Git/Git.h index 1bf3c927a..eb18a0906 100644 --- a/src/Git/Git.h +++ b/src/Git/Git.h @@ -465,7 +465,7 @@ public: { shortname = ref.Right(ref.GetLength() - prefix.GetLength()); if (shortname.Right(3) == _T("^{}")) - shortname=shortname.Left(shortname.GetLength() - 3); + shortname.Truncate(shortname.GetLength() - 3); return TRUE; } return FALSE; diff --git a/src/Git/GitAdminDir.cpp b/src/Git/GitAdminDir.cpp index 17b29cf5e..588f77261 100644 --- a/src/Git/GitAdminDir.cpp +++ b/src/Git/GitAdminDir.cpp @@ -45,7 +45,7 @@ CString GitAdminDir::GetSuperProjectRoot(const CString& path) return _T(""); } - projectroot = projectroot.Left(projectroot.ReverseFind('\\')); + projectroot.Truncate(max(0, projectroot.ReverseFind(L'\\'))); // don't check for \\COMPUTERNAME\.git if (projectroot[0] == _T('\\') && projectroot[1] == _T('\\') && projectroot.Find(_T('\\'), 2) < 0) @@ -87,7 +87,7 @@ bool GitAdminDir::HasAdminDir(const CString& path, bool bDir, CString* ProjectTo // e.g "C:\" if (path.GetLength() <= 3) return false; - sDirName = path.Left(path.ReverseFind(_T('\\'))); + sDirName.Truncate(max(0, sDirName.ReverseFind(L'\\'))); } // a .git dir or anything inside it should be left out, only interested in working copy files -- Myagi @@ -124,7 +124,7 @@ bool GitAdminDir::HasAdminDir(const CString& path, bool bDir, CString* ProjectTo if (x < 2) break; - sDirName = sDirName.Left(x); + sDirName.Truncate(x); // don't check for \\COMPUTERNAME\.git if (sDirName[0] == _T('\\') && sDirName[1] == _T('\\') && sDirName.Find(_T('\\'), 2) < 0) break; diff --git a/src/Git/GitIndex.cpp b/src/Git/GitIndex.cpp index f2f298fdd..b9142a532 100644 --- a/src/Git/GitIndex.cpp +++ b/src/Git/GitIndex.cpp @@ -769,7 +769,7 @@ int CGitIgnoreItem::FetchIgnoreList(const CString &projectroot, const CString &f int start = base.ReverseFind(_T('/')); if(start > 0) { - base = base.Left(start); + base.Truncate(start); this->m_BaseDir = CUnicodeUtils::GetMulti(base, CP_UTF8) + "/"; } } @@ -907,7 +907,7 @@ bool CGitIgnoreList::CheckIgnoreChanged(const CString &gitdir, const CString &pa { int x = temp.ReverseFind(_T('\\')); if (x >= 2) - temp = temp.Left(x); + temp.Truncate(x); } while(!temp.IsEmpty()) @@ -948,7 +948,7 @@ bool CGitIgnoreList::CheckIgnoreChanged(const CString &gitdir, const CString &pa break; } - temp = temp.Left(i); + temp.Truncate(i); } return true; } @@ -980,7 +980,7 @@ int CGitIgnoreList::LoadAllIgnoreFile(const CString &gitdir, const CString &path { int x = temp.ReverseFind(_T('\\')); if (x >= 2) - temp = temp.Left(x); + temp.Truncate(x); } while (!temp.IsEmpty()) @@ -1032,7 +1032,7 @@ int CGitIgnoreList::LoadAllIgnoreFile(const CString &gitdir, const CString &path break; } - temp = temp.Left(i); + temp.Truncate(i); } return 0; } @@ -1126,7 +1126,7 @@ bool CGitIgnoreList::IsIgnore(CString str, const CString& projectroot, bool isDi str.Replace(_T('\\'),_T('/')); if (!str.IsEmpty() && str[str.GetLength() - 1] == _T('/')) - str = str.Left(str.GetLength() - 1); + str.Truncate(str.GetLength() - 1); int ret; ret = CheckIgnore(str, projectroot, isDir); @@ -1136,7 +1136,7 @@ bool CGitIgnoreList::IsIgnore(CString str, const CString& projectroot, bool isDi if(start < 0) return (ret == 1); - str = str.Left(start); + str.Truncate(start); ret = CheckIgnore(str, projectroot, isDir); } @@ -1166,7 +1166,7 @@ int CGitIgnoreList::CheckIgnore(const CString &path, const CString &projectroot, // we do not need to check for a .ignore file inside a directory we might ignore int i = temp.ReverseFind(_T('\\')); if (i >= 0) - temp = temp.Left(i); + temp.Truncate(i); } else { @@ -1174,7 +1174,7 @@ int CGitIgnoreList::CheckIgnore(const CString &path, const CString &projectroot, int x = temp.ReverseFind(_T('\\')); if (x >= 2) - temp = temp.Left(x); + temp.Truncate(x); } int pos = patha.ReverseFind('/'); @@ -1223,7 +1223,7 @@ int CGitIgnoreList::CheckIgnore(const CString &path, const CString &projectroot, break; } - temp = temp.Left(i); + temp.Truncate(i); } return ret; diff --git a/src/Git/GitPatch.cpp b/src/Git/GitPatch.cpp index 6df4e9229..c47f23bad 100644 --- a/src/Git/GitPatch.cpp +++ b/src/Git/GitPatch.cpp @@ -280,9 +280,10 @@ CString GitPatch::CheckPatchPath(const CString& path) // now go up the tree and try again CString upperpath = path; - while (upperpath.ReverseFind('\\')>0) + int trimPos; + while ((trimPos = upperpath.ReverseFind(L'\\')) > 0) { - upperpath = upperpath.Left(upperpath.ReverseFind('\\')); + upperpath.Truncate(trimPos); progress.SetLine(2, upperpath, true); if (progress.HasUserCancelled()) return path; @@ -311,9 +312,9 @@ CString GitPatch::CheckPatchPath(const CString& path) // But: we can compare paths strings without the filenames // and check if at least those match upperpath = path; - while (upperpath.ReverseFind('\\')>0) + while ((trimPos = upperpath.ReverseFind(L'\\')) > 0) { - upperpath = upperpath.Left(upperpath.ReverseFind('\\')); + upperpath.Truncate(trimPos); progress.SetLine(2, upperpath, true); if (progress.HasUserCancelled()) return path; @@ -350,7 +351,7 @@ int GitPatch::CountDirMatches(const CString& path) const if (PathIsRelative(temp)) temp = path + _T("\\")+ temp; // remove the filename - temp = temp.Left(temp.ReverseFind('\\')); + temp.Truncate(max(0, temp.ReverseFind(L'\\'))); if (PathFileExists(temp)) ++matches; } diff --git a/src/Git/GitStatus.cpp b/src/Git/GitStatus.cpp index b8a459d5f..3a9b0d459 100644 --- a/src/Git/GitStatus.cpp +++ b/src/Git/GitStatus.cpp @@ -700,7 +700,7 @@ bool GitStatus::IsExistIndexLockFile(CString sDirName) if (x < 2) return false; - sDirName = sDirName.Left(x); + sDirName.Truncate(x); } for (;;) @@ -717,7 +717,7 @@ bool GitStatus::IsExistIndexLockFile(CString sDirName) if (x < 2) return false; - sDirName = sDirName.Left(x); + sDirName.Truncate(x); } } #endif diff --git a/src/Git/TGitPath.cpp b/src/Git/TGitPath.cpp index d7468bc20..3eb2fc5c5 100644 --- a/src/Git/TGitPath.cpp +++ b/src/Git/TGitPath.cpp @@ -501,9 +501,8 @@ CString CTGitPath::GetBaseFilename() const CString filename=GetFilename(); dot = filename.ReverseFind(_T('.')); if(dot>0) - return filename.Left(dot); - else - return filename; + filename.Truncate(dot); + return filename; } bool CTGitPath::ArePathStringsEqual(const CString& sP1, const CString& sP2) diff --git a/src/TortoiseProc/AppUtils.cpp b/src/TortoiseProc/AppUtils.cpp index 55ff502d6..e91abae41 100644 --- a/src/TortoiseProc/AppUtils.cpp +++ b/src/TortoiseProc/AppUtils.cpp @@ -2194,7 +2194,7 @@ CString CAppUtils::GetClipboardLink(const CString &skipGitPrefix, int paramsCoun break; } if (spacePos > 0 && paramsCount < 0) - sClipboardText = sClipboardText.Left(spacePos); + sClipboardText.Truncate(spacePos); return sClipboardText; } } @@ -2328,7 +2328,7 @@ int CAppUtils::SaveCommitUnicodeFile(const CString& filename, CString &message) CString line = message.Mid(oldStart); if (start != -1) { - line = line.Left(start - oldStart); + line.Truncate(start - oldStart); ++start; // move forward so we don't find the same char again } if (stripComments && (!line.IsEmpty() && line.GetAt(0) == commentChar) || (start < 0 && line.IsEmpty())) @@ -2947,7 +2947,7 @@ void CAppUtils::RemoveTrailSlash(CString &path) while(path[path.GetLength()-1] == _T('\\') || path[path.GetLength()-1] == _T('/' ) ) { - path=path.Left(path.GetLength()-1); + path.Truncate(path.GetLength() - 1); if(path.IsEmpty()) return; } @@ -3587,7 +3587,7 @@ int CAppUtils::ExploreTo(HWND hwnd, CString path) int pos = path.ReverseFind(_T('\\')); if (pos <= 3) break; - path = path.Left(pos); + path.Truncate(pos); } while (!PathFileExists(path)); return (INT_PTR)ShellExecute(hwnd, _T("explore"), path, nullptr, nullptr, SW_SHOW) > 32 ? 0 : -1; } diff --git a/src/TortoiseProc/CommitDlg.cpp b/src/TortoiseProc/CommitDlg.cpp index c93d57c7f..53ffc33ad 100644 --- a/src/TortoiseProc/CommitDlg.cpp +++ b/src/TortoiseProc/CommitDlg.cpp @@ -1672,7 +1672,7 @@ void CCommitDlg::ParseRegexFile(const CString& sFile, std::map { if (strLine.IsEmpty()) continue; - if (strLine.Left(1) == L'#') + if (strLine[0] == L'#') continue; int eqpos = strLine.Find('='); CString rgx; @@ -1705,7 +1705,7 @@ void CCommitDlg::ParseSnippetFile(const CString& sFile, std::map