From 4022b9eb49d65c8d514d945a1229af9fd66732ba Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Sat, 24 Dec 2016 01:55:56 +0100 Subject: [PATCH] Performance optimization: Use less intermediates Signed-off-by: Sven Strickroth --- src/Git/GitIndex.cpp | 55 +++++++++++++++++++++------------------------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/src/Git/GitIndex.cpp b/src/Git/GitIndex.cpp index 039ce2ab5..21f5d3b3d 100644 --- a/src/Git/GitIndex.cpp +++ b/src/Git/GitIndex.cpp @@ -927,20 +927,20 @@ bool CGitIgnoreList::CheckAndUpdateIgnoreFiles(const CString& gitdir, const CStr bool updated = false; while (!temp.IsEmpty()) { - CString tempOrig = temp; - temp += L"\\.git"; + temp += L"\\.gitignore"; + if (CheckFileChanged(temp)) + { + FetchIgnoreFile(gitdir, temp, false); + updated = true; + } + + temp.Truncate(temp.GetLength() - (int)wcslen(L"ignore")); if (CGit::GitPathFileExists(temp)) { - CString gitignore = temp; - gitignore += L"ignore"; - if (CheckFileChanged(gitignore)) - { - FetchIgnoreFile(gitdir, gitignore, false); - updated = true; - } + temp.Truncate(temp.GetLength() - (int)wcslen(L"\\.git")); - CString adminDir = g_AdminDirMap.GetAdminDir(tempOrig); + CString adminDir = g_AdminDirMap.GetAdminDir(temp); CString wcglobalgitignore = adminDir + L"info\\exclude"; if (CheckFileChanged(wcglobalgitignore)) { @@ -965,13 +965,6 @@ bool CGitIgnoreList::CheckAndUpdateIgnoreFiles(const CString& gitdir, const CStr return updated; } - temp += L"ignore"; - if (CheckFileChanged(temp)) - { - FetchIgnoreFile(gitdir, temp, false); - updated = true; - } - int found = 0; int i; for (i = temp.GetLength() - 1; i >= 0; --i) @@ -1137,33 +1130,29 @@ int CGitIgnoreList::CheckIgnore(const CString &path, const CString &projectroot, CAutoReadLock lock(m_SharedMutex); while (!temp.IsEmpty()) { - CString tempOrig = temp; - temp += L"\\.git"; + temp += L"\\.gitignore"; + + if ((ret = CheckFileAgainstIgnoreList(temp, patha, base, type)) != -1) + return ret; + + temp.Truncate(temp.GetLength() - (int)wcslen(L"ignore")); if (CGit::GitPathFileExists(temp)) { - CString gitignore = temp; - gitignore += L"ignore"; - if ((ret = CheckFileAgainstIgnoreList(gitignore, patha, base, type)) != -1) - break; - - CString adminDir = g_AdminDirMap.GetAdminDir(tempOrig); + temp.Truncate(temp.GetLength() - (int)wcslen(L"\\.git")); + CString adminDir = g_AdminDirMap.GetAdminDir(temp); CString wcglobalgitignore = adminDir; wcglobalgitignore += L"info\\exclude"; if ((ret = CheckFileAgainstIgnoreList(wcglobalgitignore, patha, base, type)) != -1) - break; + return ret; CString excludesFile = m_CoreExcludesfiles[adminDir]; if (!excludesFile.IsEmpty()) - ret = CheckFileAgainstIgnoreList(excludesFile, patha, base, type); + return CheckFileAgainstIgnoreList(excludesFile, patha, base, type); - break; + return -1; } - temp += L"ignore"; - if ((ret = CheckFileAgainstIgnoreList(temp, patha, base, type)) != -1) - break; - int found = 0; int i; for (i = temp.GetLength() - 1; i >= 0; i--) @@ -1178,7 +1167,7 @@ int CGitIgnoreList::CheckIgnore(const CString &path, const CString &projectroot, temp.Truncate(max(0, i)); } - return ret; + return -1; } bool CGitHeadFileMap::CheckHeadAndUpdate(const CString &gitdir, bool readTree /* = true */) -- 2.11.4.GIT