From 05be1aade21b57550527d41a5385a093c9a4c855 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Sat, 8 Aug 2015 22:23:50 +0200 Subject: [PATCH] Performance optimization Signed-off-by: Sven Strickroth --- src/Git/Git.cpp | 28 ++++++++++++++++++++++------ src/Git/TGitPath.cpp | 30 ++++++++++++++++-------------- src/Git/TGitPath.h | 2 +- src/TortoiseProc/GitLogListAction.cpp | 10 +++++----- 4 files changed, 44 insertions(+), 26 deletions(-) diff --git a/src/Git/Git.cpp b/src/Git/Git.cpp index 2a6d95ee9..b63cb32a5 100644 --- a/src/Git/Git.cpp +++ b/src/Git/Git.cpp @@ -3255,6 +3255,10 @@ int CGit::GetWorkingTreeChanges(CTGitPathList& result, bool amend, CTGitPathList } result.ParserFromLog(out); + std::map duplicateMap; + for (int i = 0; i < result.GetCount(); ++i) + duplicateMap.insert(std::pair(result[i].GetGitPathString(), i)); + // handle delete conflict case, when remote : modified, local : deleted. for (int i = 0; i < count; ++i) { @@ -3272,11 +3276,17 @@ int CGit::GetWorkingTreeChanges(CTGitPathList& result, bool amend, CTGitPathList conflictlist.ParserFromLog(cmdout); for (int j = 0; j < conflictlist.GetCount(); ++j) { - CTGitPath* p = result.LookForGitPath(conflictlist[j].GetGitPathString()); - if (p) - p->m_Action |= CTGitPath::LOGACTIONS_UNMERGED; + auto existing = duplicateMap.find(conflictlist[j].GetGitPathString()); + if (existing != duplicateMap.end()) + { + CTGitPath& p = const_cast(result[existing->second]); + p.m_Action |= CTGitPath::LOGACTIONS_UNMERGED; + } else + { result.AddPath(conflictlist[j]); + duplicateMap.insert(std::pair(result[i].GetGitPathString(), result.GetCount() - 1)); + } } } @@ -3298,11 +3308,17 @@ int CGit::GetWorkingTreeChanges(CTGitPathList& result, bool amend, CTGitPathList deletelist.ParserFromLog(cmdout, true); for (int j = 0; j < deletelist.GetCount(); ++j) { - CTGitPath* p = result.LookForGitPath(deletelist[j].GetGitPathString()); - if (!p) + auto existing = duplicateMap.find(deletelist[j].GetGitPathString()); + if (existing == duplicateMap.end()) + { result.AddPath(deletelist[j]); + duplicateMap.insert(std::pair(result[i].GetGitPathString(), result.GetCount() - 1)); + } else - p->m_Action |= CTGitPath::LOGACTIONS_MISSING; + { + CTGitPath& p = const_cast(result[existing->second]); + p.m_Action |= CTGitPath::LOGACTIONS_MISSING; + } } } diff --git a/src/Git/TGitPath.cpp b/src/Git/TGitPath.cpp index 63b34cfd1..4f0aca530 100644 --- a/src/Git/TGitPath.cpp +++ b/src/Git/TGitPath.cpp @@ -1162,6 +1162,7 @@ int CTGitPathList::FillBasedOnIndexFlags(unsigned short flag, CTGitPathList* lis int CTGitPathList::ParserFromLog(BYTE_VECTOR &log, bool parseDeletes /*false*/) { this->Clear(); + std::map duplicateMap; int pos=0; CTGitPath path; m_Action=0; @@ -1225,19 +1226,18 @@ int CTGitPathList::ParserFromLog(BYTE_VECTOR &log, bool parseDeletes /*false*/) if( file2>=0 ) CGit::StringAppend(&pathname2, &log[file2], CP_UTF8); - CTGitPath *GitPath=LookForGitPath(pathname1); - if (actionstart < 0) return -1; - if(GitPath) + + auto existing = duplicateMap.find(pathname1); + if (existing != duplicateMap.end()) { - GitPath->ParserAction( log[actionstart] ); + CTGitPath& p = m_paths[existing->second]; + p.ParserAction(log[actionstart]); if(merged) - { - GitPath->m_Action |= CTGitPath::LOGACTIONS_MERGED; - } - m_Action |=GitPath->m_Action; + p.m_Action |= CTGitPath::LOGACTIONS_MERGED; + m_Action |= p.m_Action; } else @@ -1251,7 +1251,7 @@ int CTGitPathList::ParserFromLog(BYTE_VECTOR &log, bool parseDeletes /*false*/) this->m_Action|=ac; AddPath(path); - + duplicateMap.insert(std::pair(path.GetGitPathString(), m_paths.size() - 1)); } } @@ -1300,11 +1300,12 @@ int CTGitPathList::ParserFromLog(BYTE_VECTOR &log, bool parseDeletes /*false*/) } path.SetFromGit(file1,&file2); - CTGitPath *GitPath=LookForGitPath(path.GetGitPathString()); - if(GitPath) + auto existing = duplicateMap.find(path.GetGitPathString()); + if (existing != duplicateMap.end()) { - GitPath->m_StatAdd=StatAdd; - GitPath->m_StatDel=StatDel; + CTGitPath& p = m_paths[existing->second]; + p.m_StatAdd = StatAdd; + p.m_StatDel = StatDel; } else { @@ -1321,6 +1322,7 @@ int CTGitPathList::ParserFromLog(BYTE_VECTOR &log, bool parseDeletes /*false*/) path.m_StatDel=StatDel; } AddPath(path); + duplicateMap.insert(std::pair(path.GetGitPathString(), m_paths.size() - 1)); } } @@ -1666,7 +1668,7 @@ bool CTGitPathList::IsEqual(const CTGitPathList& list) return true; } -CTGitPath * CTGitPathList::LookForGitPath(CString path) +const CTGitPath* CTGitPathList::LookForGitPath(const CString& path) { int i=0; for (i = 0; i < this->GetCount(); ++i) diff --git a/src/Git/TGitPath.h b/src/Git/TGitPath.h index 3ad9891f8..185d3480c 100644 --- a/src/Git/TGitPath.h +++ b/src/Git/TGitPath.h @@ -351,7 +351,7 @@ public: void AddPath(const CTGitPath& newPath); bool LoadFromFile(const CTGitPath& filename); bool WriteToFile(const CString& sFilename, bool bANSI = false) const; - CTGitPath * LookForGitPath(CString path); + const CTGitPath* LookForGitPath(const CString& path); int ParserFromLog(BYTE_VECTOR &log, bool parseDeletes = false); int ParserFromLsFile(BYTE_VECTOR &out,bool staged=true); int FillUnRev(unsigned int Action, CTGitPathList *list = nullptr, CString *err = nullptr); diff --git a/src/TortoiseProc/GitLogListAction.cpp b/src/TortoiseProc/GitLogListAction.cpp index 7892be2e4..67a51003c 100644 --- a/src/TortoiseProc/GitLogListAction.cpp +++ b/src/TortoiseProc/GitLogListAction.cpp @@ -271,7 +271,7 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe { GitRevLoglist* first = reinterpret_cast(m_arShownList.GetAt(i)); CTGitPathList list = first->GetFiles(NULL); - CTGitPath * file = list.LookForGitPath(path1); + const CTGitPath* file = list.LookForGitPath(path1); if (file && !file->GetGitOldPathString().IsEmpty()) path1 = file->GetGitOldPathString(); } @@ -280,7 +280,7 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe { GitRevLoglist* first = reinterpret_cast(m_arShownList.GetAt(i)); CTGitPathList list = first->GetFiles(NULL); - CTGitPath * file = list.LookForGitPath(path2); + const CTGitPath* file = list.LookForGitPath(path2); if (file && !file->GetGitOldPathString().IsEmpty()) path2 = file->GetGitOldPathString(); } @@ -305,7 +305,7 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe { GitRevLoglist* first = reinterpret_cast(m_arShownList.GetAt(i)); CTGitPathList list = first->GetFiles(NULL); - CTGitPath * file = list.LookForGitPath(path1); + const CTGitPath* file = list.LookForGitPath(path1); if (file && !file->GetGitOldPathString().IsEmpty()) path1 = file->GetGitOldPathString(); } @@ -354,14 +354,14 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe { GitRevLoglist* first = reinterpret_cast(m_arShownList.GetAt(i)); CTGitPathList list = first->GetFiles(NULL); - CTGitPath * file = list.LookForGitPath(path1); + const CTGitPath* file = list.LookForGitPath(path1); if (file && !file->GetGitOldPathString().IsEmpty()) path1 = file->GetGitOldPathString(); } CString path2 = path1; GitRevLoglist* first = reinterpret_cast(m_arShownList.GetAt(indexNext)); CTGitPathList list = first->GetFiles(NULL); - CTGitPath * file = list.LookForGitPath(path2); + const CTGitPath* file = list.LookForGitPath(path2); if (file && !file->GetGitOldPathString().IsEmpty()) path2 = file->GetGitOldPathString(); -- 2.11.4.GIT