From: sdottaka Date: Sat, 4 Jan 2014 07:50:01 +0000 (+0900) Subject: * Reduce memory usage while comparing folders(3) X-Git-Tag: 2.16.5~1527^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=92b10eb4e5f0ffe0b3ddec867902cf91a485be60;p=winmerge-jp%2Fwinmerge-jp.git * Reduce memory usage while comparing folders(3) (Use boost::flyweight instead of boost::shared_ptr) --HG-- branch : stable --- diff --git a/Src/DiffThread.cpp b/Src/DiffThread.cpp index f1ca729e2..fa1c41d99 100644 --- a/Src/DiffThread.cpp +++ b/Src/DiffThread.cpp @@ -160,9 +160,7 @@ static void DiffThreadCollect(void *pParam) paths = myStruct->context->GetNormalizedPaths(); - shared_ptr subdir[3]; // blank to start at roots specified in diff context - subdir[0].reset(new String(_T(""))); - subdir[1] = subdir[2] = subdir[0]; + String subdir[3] = {_T(""), _T(""), _T("")}; // blank to start at roots specified in diff context // Build results list (except delaying file comparisons until below) DirScan_GetItems(paths, subdir, myStruct, diff --git a/Src/DirItem.cpp b/Src/DirItem.cpp index ad1c669b7..60cc33148 100644 --- a/Src/DirItem.cpp +++ b/Src/DirItem.cpp @@ -74,7 +74,7 @@ void DirItem::SetFile(const String &fullPath) */ String DirItem::GetFile() const { - return paths_ConcatPath(*path, *filename); + return paths_ConcatPath(path.get(), filename.get()); } /** diff --git a/Src/DirItem.h b/Src/DirItem.h index cb833da6a..c45486f94 100644 --- a/Src/DirItem.h +++ b/Src/DirItem.h @@ -32,6 +32,7 @@ #include #include #include +#include /** * @brief Class for fileflags. @@ -58,18 +59,18 @@ struct DirItem Poco::Timestamp ctime; /**< time of creation */ Poco::Timestamp mtime; /**< time of last modify */ Poco::File::FileSize size; /**< file size in bytes, -1 means file does not exist*/ - boost::shared_ptr filename; /**< filename for this item */ - boost::shared_ptr path; /**< full path (excluding filename) for the item */ + boost::flyweight filename; /**< filename for this item */ + boost::flyweight path; /**< full path (excluding filename) for the item */ FileVersion version; /**< string of fixed file version, eg, 1.2.3.4 */ FileFlags flags; /**< file attributes */ DirItem() : ctime(0), mtime(0), size(-1) { } void SetFile(const String &fullPath); String GetFile() const; - const String& GetPath() const { return *path; }; - void SetPath(const String& newpath) { path.reset(new String(newpath)); } - const String& GetFileName() const { return *filename; }; - void SetFileName(const String& newfilename) { filename.reset(new String(newfilename)); } + const String& GetPath() const { return path.get(); }; + void SetPath(const String& newpath) { path = newpath; } + const String& GetFileName() const { return filename.get(); }; + void SetFileName(const String& newfilename) { filename = newfilename; } bool Update(const String &sFilePath); void ClearPartial(); }; diff --git a/Src/DirScan.cpp b/Src/DirScan.cpp index 4ef2d53db..09778ae38 100644 --- a/Src/DirScan.cpp +++ b/Src/DirScan.cpp @@ -51,9 +51,9 @@ using boost::shared_ptr; void CompareDiffItem(DIFFITEM &di, CDiffContext * pCtxt); static void StoreDiffData(DIFFITEM &di, CDiffContext * pCtxt, const FolderCmp * pCmpData); -static DIFFITEM *AddToList(const shared_ptr sLeftDir, const shared_ptr sRightDir, const DirItem * lent, const DirItem * rent, +static DIFFITEM *AddToList(const String& sLeftDir, const String& sRightDir, const DirItem * lent, const DirItem * rent, unsigned code, DiffFuncStruct *myStruct, DIFFITEM *parent); -static DIFFITEM *AddToList(const shared_ptr sLeftDir, const shared_ptr sMiddleDir, const shared_ptr sRightDir, const DirItem * lent, const DirItem * ment, const DirItem * rent, +static DIFFITEM *AddToList(const String& sLeftDir, const String& sMiddleDir, const String& sRightDir, const DirItem * lent, const DirItem * ment, const DirItem * rent, unsigned code, DiffFuncStruct *myStruct, DIFFITEM *parent); static void UpdateDiffItem(DIFFITEM & di, bool & bExists, CDiffContext *pCtxt); static int CompareItems(NotificationQueue& queue, DiffFuncStruct *myStruct, UIntPtr parentdiffpos); @@ -133,7 +133,7 @@ typedef boost::shared_ptr DiffWorkerPtr; * @param [in] bUniques If true, walk into unique folders. * @return 1 normally, -1 if compare was aborted */ -int DirScan_GetItems(const PathContext &paths, const shared_ptr subdir[], +int DirScan_GetItems(const PathContext &paths, const String subdir[], DiffFuncStruct *myStruct, bool casesensitive, int depth, DIFFITEM *parent, bool bUniques) @@ -148,12 +148,12 @@ int DirScan_GetItems(const PathContext &paths, const shared_ptr subdir[] for (nIndex = 0; nIndex < nDirs; nIndex++) sDir[nIndex] = paths.GetPath(nIndex); - if (!subdir[0]->empty()) + if (!subdir[0].empty()) { for (nIndex = 0; nIndex < paths.GetSize(); nIndex++) { - sDir[nIndex] = paths_ConcatPath(sDir[nIndex], *subdir[nIndex]); - subprefix[nIndex] = *subdir[nIndex] + backslash; + sDir[nIndex] = paths_ConcatPath(sDir[nIndex], subdir[nIndex]); + subprefix[nIndex] = subdir[nIndex] + backslash; } } @@ -351,12 +351,7 @@ OutputDebugString(buf); nDiffCode & DIFFCODE::SECOND ? &dirs[1][j] : NULL, nDiffCode, myStruct, parent); // Scan recursively all subdirectories too, we are not adding folders - shared_ptr newsubdir[3]; - newsubdir[0].reset(new String(leftnewsub)); - if (leftnewsub == rightnewsub) - newsubdir[1] = newsubdir[0]; - else - newsubdir[1].reset(new String(rightnewsub)); + String newsubdir[3] = {leftnewsub, rightnewsub}; int result = DirScan_GetItems(paths, newsubdir, myStruct, casesensitive, depth - 1, me, bUniques); if (result == -1) @@ -402,16 +397,7 @@ OutputDebugString(buf); nDiffCode & DIFFCODE::THIRD ? &dirs[2][k] : NULL, nDiffCode, myStruct, parent); // Scan recursively all subdirectories too, we are not adding folders - shared_ptr newsubdir[3]; - newsubdir[0].reset(new String(leftnewsub)); - if (leftnewsub == middlenewsub) - newsubdir[1] = newsubdir[0]; - else - newsubdir[1].reset(new String(middlenewsub)); - if (leftnewsub == rightnewsub) - newsubdir[2] = newsubdir[0]; - else - newsubdir[2].reset(new String(rightnewsub)); + String newsubdir[3] = {leftnewsub, middlenewsub, rightnewsub}; int result = DirScan_GetItems(paths, newsubdir, myStruct, casesensitive, depth - 1, me, bUniques); if (result == -1) @@ -882,7 +868,7 @@ static void StoreDiffData(DIFFITEM &di, CDiffContext * pCtxt, * @param [in] pCtxt Compare context. * @param [in] parent Parent of item to be added */ -static DIFFITEM *AddToList(const shared_ptr sLeftDir, const shared_ptr sRightDir, +static DIFFITEM *AddToList(const String& sLeftDir, const String& sRightDir, const DirItem * lent, const DirItem * rent, unsigned code, DiffFuncStruct *myStruct, DIFFITEM *parent) { @@ -892,7 +878,7 @@ static DIFFITEM *AddToList(const shared_ptr sLeftDir, const shared_ptr sLeftDir, const shared_ptr sMiddleDir, const shared_ptr sRightDir, +static DIFFITEM *AddToList(const String& sLeftDir, const String& sMiddleDir, const String& sRightDir, const DirItem * lent, const DirItem * ment, const DirItem * rent, unsigned code, DiffFuncStruct *myStruct, DIFFITEM *parent) { @@ -925,8 +911,7 @@ static DIFFITEM *AddToList(const shared_ptr sLeftDir, const shared_ptrdiffFileInfo[1].filename = - (*di->diffFileInfo[0].filename == *ment->filename) ? di->diffFileInfo[0].filename : ment->filename; + di->diffFileInfo[1].filename = ment->filename; di->diffFileInfo[1].mtime = ment->mtime; di->diffFileInfo[1].ctime = ment->ctime; di->diffFileInfo[1].size = ment->size; @@ -943,8 +928,7 @@ static DIFFITEM *AddToList(const shared_ptr sLeftDir, const shared_ptrdiffFileInfo[2].filename = - (*di->diffFileInfo[0].filename == *rent->filename) ? di->diffFileInfo[0].filename : rent->filename; + di->diffFileInfo[2].filename = rent->filename; di->diffFileInfo[2].mtime = rent->mtime; di->diffFileInfo[2].ctime = rent->ctime; di->diffFileInfo[2].size = rent->size; diff --git a/Src/DirScan.h b/Src/DirScan.h index cbea8e015..f7b3825da 100644 --- a/Src/DirScan.h +++ b/Src/DirScan.h @@ -12,7 +12,6 @@ #include "UnicodeString.h" #define POCO_NO_UNWINDOWS 1 #include -#include class CDiffContext; class DiffItemList; @@ -21,7 +20,7 @@ class IAbortable; struct DIFFITEM; struct DiffFuncStruct; -int DirScan_GetItems(const PathContext &paths, const boost::shared_ptr subdir[], DiffFuncStruct *myStruct, +int DirScan_GetItems(const PathContext &paths, const String subdir[], DiffFuncStruct *myStruct, bool casesensitive, int depth, DIFFITEM *parent, bool bUniques); int DirScan_CompareItems(DiffFuncStruct *, Poco::UIntPtr parentdiffpos); diff --git a/Src/DirTravel.cpp b/Src/DirTravel.cpp index e415f37c6..2db1f0e83 100644 --- a/Src/DirTravel.cpp +++ b/Src/DirTravel.cpp @@ -50,7 +50,7 @@ void LoadAndSortFiles(const String& sDir, DirItemArray * dirs, DirItemArray * fi */ static void LoadFiles(const String& sDir, DirItemArray * dirs, DirItemArray * files) { - shared_ptr pdir(new String(sDir)); + boost::flyweight dir(sDir); #if 0 DirectoryIterator it(ucr::toUTF8(sDir)); DirectoryIterator end; @@ -69,8 +69,8 @@ static void LoadFiles(const String& sDir, DirItemArray * dirs, DirItemArray * fi if (ent.mtime < 0) ent.mtime = 0; ent.size = it->getSize(); - ent.path = pdir; - ent.filename.reset(new String(ucr::toTString(it.name())); + ent.path = dir; + ent.filename = ucr::toTString(it.name()); #ifdef _WIN32 ent.flags.attributes = GetFileAttributes(ucr::toTString(it.name()).c_str());; #else @@ -117,8 +117,8 @@ static void LoadFiles(const String& sDir, DirItemArray * dirs, DirItemArray * fi ent.size = ((Int64)ff.nFileSizeHigh << 32) + ff.nFileSizeLow; } - ent.path = pdir; - ent.filename.reset(new String(ff.cFileName)); + ent.path = dir; + ent.filename = ff.cFileName; ent.flags.attributes = ff.dwFileAttributes; (bIsDirectory ? dirs : files)->push_back(ent);