From: sdottaka Date: Mon, 30 Dec 2013 06:28:00 +0000 (+0900) Subject: * Reduce memory usage while comparing folders X-Git-Tag: 2.16.4+-jp-10~975^2~6 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=3381926666f2ffbae85a85b95668d6cf01579bec;p=winmerge-jp%2Fwinmerge-jp.git * Reduce memory usage while comparing folders (remove unused member variables) * Remove DiffFileFlags class and move DiffFileFlags::ToString() to FileFlags class --HG-- branch : stable --- diff --git a/Src/Common/UniFile.cpp b/Src/Common/UniFile.cpp index c12391a7d..2c1d8f929 100644 --- a/Src/Common/UniFile.cpp +++ b/Src/Common/UniFile.cpp @@ -425,9 +425,6 @@ static void Append(String &strBuffer, const TCHAR *pchTail, static void RecordZero(UniFile::txtstats & txstats, Int64 offset) { ++txstats.nzeros; - if (txstats.first_zero == -1) - txstats.first_zero = offset; - txstats.last_zero = offset; } /** diff --git a/Src/Common/UniFile.h b/Src/Common/UniFile.h index 758033265..b29db83dd 100644 --- a/Src/Common/UniFile.h +++ b/Src/Common/UniFile.h @@ -69,11 +69,9 @@ public: int nlfs; int ncrlfs; int nzeros; - Poco::Int64 first_zero; // byte offset, initially -1 - Poco::Int64 last_zero; // byte offset, initially -1 int nlosses; txtstats() { clear(); } - void clear() { ncrs = nlfs = ncrlfs = nzeros = nlosses = 0; first_zero = -1; last_zero = -1; } + void clear() { ncrs = nlfs = ncrlfs = nzeros = nlosses = 0; } }; virtual const txtstats & GetTxtStats() const = 0; }; diff --git a/Src/Common/unicoder.h b/Src/Common/unicoder.h index de632e234..eb8d93124 100644 --- a/Src/Common/unicoder.h +++ b/Src/Common/unicoder.h @@ -36,6 +36,9 @@ struct buffer /** @brief Known Unicode encodings. */ enum UNICODESET +#if __cplusplus >= 201103L || _MSC_VER >= 1600 + : char +#endif { NONE = 0, /**< No unicode. */ UCS2LE, /**< UCS-2 / UTF-16 little endian. */ diff --git a/Src/CompareEngines/ByteComparator.cpp b/Src/CompareEngines/ByteComparator.cpp index 401cd640c..0ad1eaff8 100644 --- a/Src/CompareEngines/ByteComparator.cpp +++ b/Src/CompareEngines/ByteComparator.cpp @@ -71,10 +71,6 @@ static void TextScan(FileTextStats & stats, const char *ptr, const char *end, bo if (ch == 0) { ++stats.nzeros; - Int64 index = offset + (ptr - start); - if (stats.first_zero == -1) - stats.first_zero = index; - stats.last_zero = index; } else if (ch == '\r') { diff --git a/Src/DiffFileInfo.cpp b/Src/DiffFileInfo.cpp index fb456c001..1e9e6e7d5 100644 --- a/Src/DiffFileInfo.cpp +++ b/Src/DiffFileInfo.cpp @@ -30,36 +30,6 @@ #include "UnicodeString.h" /** - * @brief Convert file flags to string presentation. - * This function converts file flags to a string presentation that can be - * shown in the GUI. - * @return File flags as a string. - */ -String DiffFileFlags::ToString() const -{ - String sflags; -#ifdef _WIN32 - if (attributes & FILE_ATTRIBUTE_READONLY) - sflags += _T("R"); - if (attributes & FILE_ATTRIBUTE_HIDDEN) - sflags += _T("H"); - if (attributes & FILE_ATTRIBUTE_SYSTEM) - sflags += _T("S"); - if (attributes & FILE_ATTRIBUTE_ARCHIVE) - sflags += _T("A"); -#endif - if ((coding & coding_mask) == UTF_8) - sflags += _T("8"); - if ((coding & coding_mask) == UCS_2BE) - sflags += _T("B"); - if ((coding & coding_mask) == UCS_2LE) - sflags += _T("L"); - if ((coding & coding_mask) == UCS_4) - sflags += _T("4"); - return sflags; -} - -/** * @brief Clears FileInfo data. */ void DiffFileInfo::ClearPartial() diff --git a/Src/DiffFileInfo.h b/Src/DiffFileInfo.h index fcb48959d..7ca01cb6a 100644 --- a/Src/DiffFileInfo.h +++ b/Src/DiffFileInfo.h @@ -30,29 +30,6 @@ #include "FileTextStats.h" /** - * @brief Class for fileflags and coding info. - */ -struct DiffFileFlags : public FileFlags -{ - /** - * @brief Encodings supported. - */ - enum - { - UTF_8 = 0x1000, - UCS_4 = 0x2000, - UCS_2BE = 0x3000, - UCS_2LE = 0x4000, - coding_mask = 0x7000, - }; - - unsigned coding; /**< Coding info for item */ - DiffFileFlags() : coding(0) { } - String ToString() const; -}; - - -/** * @brief Information for file. * This class expands DirItem class with encoding information and * text stats information. @@ -62,7 +39,6 @@ struct DiffFileInfo : public DirItem { // data bool bVersionChecked; /**< true if version string is up-to-date */ - DiffFileFlags flags; /**< file attributes */ FileTextEncoding encoding; /**< unicode or codepage info */ FileTextStats m_textStats; /**< EOL, zero-byte etc counts */ diff --git a/Src/DirItem.cpp b/Src/DirItem.cpp index ce0290d20..5bd003207 100644 --- a/Src/DirItem.cpp +++ b/Src/DirItem.cpp @@ -31,6 +31,28 @@ #include "TFile.h" /** + * @brief Convert file flags to string presentation. + * This function converts file flags to a string presentation that can be + * shown in the GUI. + * @return File flags as a string. + */ +String FileFlags::ToString() const +{ + String sflags; +#ifdef _WIN32 + if (attributes & FILE_ATTRIBUTE_READONLY) + sflags += _T("R"); + if (attributes & FILE_ATTRIBUTE_HIDDEN) + sflags += _T("H"); + if (attributes & FILE_ATTRIBUTE_SYSTEM) + sflags += _T("S"); + if (attributes & FILE_ATTRIBUTE_ARCHIVE) + sflags += _T("A"); +#endif + return sflags; +} + +/** * @brief Set filename and path for the item. * @param [in] fullpath Full path to file to set to item. */ @@ -114,7 +136,6 @@ void DirItem::ClearPartial() ctime = 0; mtime = 0; size = -1; - bIsDir = false; version.Clear(); flags.reset(); } diff --git a/Src/DirItem.h b/Src/DirItem.h index 9ab7e91f9..f95d20981 100644 --- a/Src/DirItem.h +++ b/Src/DirItem.h @@ -40,6 +40,7 @@ struct FileFlags unsigned attributes; /**< Fileattributes for item */ FileFlags() : attributes(0) { } void reset() { attributes = 0; } /// Reset fileattributes + String ToString() const; }; /** @@ -58,11 +59,10 @@ struct DirItem Poco::File::FileSize size; /**< file size in bytes, -1 means file does not exist*/ String filename; /**< filename for this item */ String path; /**< full path (excluding filename) for the item */ - bool bIsDir; /**< is this a directory item or file item? */ FileVersion version; /**< string of fixed file version, eg, 1.2.3.4 */ FileFlags flags; /**< file attributes */ - DirItem() : ctime(0), mtime(0), size(-1), bIsDir(false) { } + DirItem() : ctime(0), mtime(0), size(-1) { } void SetFile(const String &fullPath); String GetFile() const; bool Update(const String &sFilePath); diff --git a/Src/DirTravel.cpp b/Src/DirTravel.cpp index e5c031599..f9db1cd6f 100644 --- a/Src/DirTravel.cpp +++ b/Src/DirTravel.cpp @@ -60,19 +60,13 @@ static void LoadFiles(const String& sDir, DirItemArray * dirs, DirItemArray * fi continue; DirItem ent; - ent.bIsDir = bIsDirectory; ent.ctime = it->created(); if (ent.ctime < 0) ent.ctime = 0; ent.mtime = it->getLastModified(); if (ent.mtime < 0) ent.mtime = 0; - - if (ent.bIsDir) - ent.size = -1; // No size for directories - else - ent.size = it->getSize(); - + ent.size = it->getSize(); ent.path = sDir; ent.filename = ucr::toTString(it.name()); #ifdef _WIN32 @@ -102,7 +96,6 @@ static void LoadFiles(const String& sDir, DirItemArray * dirs, DirItemArray * fi continue; DirItem ent; - ent.bIsDir = !!bIsDirectory; // Save filetimes as seconds since January 1, 1970 // Note that times can be < 0 if they are around that 1970.. diff --git a/Src/DirViewColItems.cpp b/Src/DirViewColItems.cpp index 5cc06f9ad..a7749a2ab 100644 --- a/Src/DirViewColItems.cpp +++ b/Src/DirViewColItems.cpp @@ -612,7 +612,7 @@ static String ColBinGet(const CDiffContext *, const void *p) */ static String ColAttrGet(const CDiffContext *, const void *p) { - const DiffFileFlags &r = *static_cast(p); + const FileFlags &r = *static_cast(p); return r.ToString(); } @@ -887,8 +887,8 @@ static int ColBinSort(const CDiffContext *, const void *p, const void *q) */ static int ColAttrSort(const CDiffContext *, const void *p, const void *q) { - const DiffFileFlags &r = *static_cast(p); - const DiffFileFlags &s = *static_cast(q); + const FileFlags &r = *static_cast(p); + const FileFlags &s = *static_cast(q); return r.ToString() == s.ToString(); } diff --git a/Src/FileTextStats.h b/Src/FileTextStats.h index 4a9aaf700..da39e067f 100644 --- a/Src/FileTextStats.h +++ b/Src/FileTextStats.h @@ -24,11 +24,8 @@ struct FileTextStats unsigned nlfs; /**< Count of Unix (LF-byte) EOLs. */ unsigned ncrlfs; /**< Count of DOS (CR+LF-bytes) EOLs. */ unsigned nzeros; /**< Count of zero-bytes. */ - Poco::Int64 first_zero; /**< Byte offset to first zero-byte, initially -1 */ - Poco::Int64 last_zero; /**< Byte offset to last zero-byte, initially -1 */ - unsigned nlosses; FileTextStats() { clear(); } - void clear() { ncrs = nlfs = ncrlfs = nzeros = nlosses = 0; first_zero = -1; last_zero = -1; } + void clear() { ncrs = nlfs = ncrlfs = nzeros = 0; } }; diff --git a/Src/FileVersion.cpp b/Src/FileVersion.cpp index ac4e7bc73..cbcb6f941 100644 --- a/Src/FileVersion.cpp +++ b/Src/FileVersion.cpp @@ -18,12 +18,8 @@ * @brief Default constructor. */ FileVersion::FileVersion() -: m_bFileVersionSet(false) -, m_fileVersionMS(0) -, m_fileVersionLS(0) -, m_bProductVersionSet(false) -, m_productVersionMS(0) -, m_productVersionLS(0) +: m_fileVersionMS(0xffffffff) +, m_fileVersionLS(0xffffffff) { } @@ -32,12 +28,7 @@ FileVersion::FileVersion() */ void FileVersion::Clear() { - m_bFileVersionSet = false; - m_fileVersionMS = 0; - m_fileVersionLS = 0; - m_bProductVersionSet = false; - m_productVersionMS = 0; - m_productVersionLS = 0; + m_fileVersionMS = m_fileVersionLS = 0xffffffff; } /** @@ -47,31 +38,18 @@ void FileVersion::Clear() */ void FileVersion::SetFileVersion(unsigned versionMS, unsigned versionLS) { - m_bFileVersionSet = true; m_fileVersionMS = versionMS; m_fileVersionLS = versionLS; } /** - * @brief Set product version number. - * @param [in] versionMS Most significant dword for version. - * @param [in] versionLS Least significant dword for version. - */ -void FileVersion::SetProductVersion(unsigned versionMS, unsigned versionLS) -{ - m_bProductVersionSet = true; - m_productVersionMS = versionMS; - m_productVersionLS = versionLS; -} - -/** * @brief Get file version as a string. * @return File version number as a string. Returns empty string if there is * no version number for the file. */ String FileVersion::GetFileVersionString() { - if (!m_bFileVersionSet) + if (m_fileVersionMS == 0xffffffff && m_fileVersionLS == 0xffffffff) return _T(""); return string_format(_T("%u.%u.%u.%u"), HIWORD(m_fileVersionMS), @@ -79,16 +57,3 @@ String FileVersion::GetFileVersionString() LOWORD(m_fileVersionLS)); } -/** - * @brief Get product version as a string. - * @return Product version number as a string. - */ -String FileVersion::GetProductVersionString() -{ - if (!m_bProductVersionSet) - return _T("0.0.0.0"); - - return string_format(_T("%u.%u.%u.%u"), HIWORD(m_productVersionMS), - LOWORD(m_productVersionMS), HIWORD(m_productVersionLS), - LOWORD(m_productVersionLS)); -} diff --git a/Src/FileVersion.h b/Src/FileVersion.h index b14aecc50..147fb8df5 100644 --- a/Src/FileVersion.h +++ b/Src/FileVersion.h @@ -19,21 +19,14 @@ class FileVersion { private: - bool m_bFileVersionSet; //*< Is file version set? */ - bool m_bProductVersionSet; //*< Is product version set? */ unsigned m_fileVersionMS; //*< File version most significant dword. */ unsigned m_fileVersionLS; //*< File version least significant dword. */ - unsigned m_productVersionMS; //*< Product version most significant dword. */ - unsigned m_productVersionLS; //*< Product version least significant dword. */ public: FileVersion(); void Clear(); void SetFileVersion(unsigned versionMS, unsigned versionLS); - void SetProductVersion(unsigned versionMS, unsigned versionLS); - String GetFileVersionString(); - String GetProductVersionString(); }; #endif // _FILE_VERSION_H_ diff --git a/Testing/GoogleTest/FileVersion/FileVersion_test.cpp b/Testing/GoogleTest/FileVersion/FileVersion_test.cpp index b2e227341..c636f115b 100644 --- a/Testing/GoogleTest/FileVersion/FileVersion_test.cpp +++ b/Testing/GoogleTest/FileVersion/FileVersion_test.cpp @@ -51,11 +51,6 @@ namespace FileVersion version; EXPECT_EQ(_T(""), version.GetFileVersionString()); } - TEST_F(FileVersionTest, getprodver_notset) - { - FileVersion version; - EXPECT_EQ(_T("0.0.0.0"), version.GetProductVersionString()); - } TEST_F(FileVersionTest, getfilever_zeros) { @@ -79,26 +74,4 @@ namespace EXPECT_EQ(_T("1.2.3.4"), version.GetFileVersionString()); } - TEST_F(FileVersionTest, getprodver_zeros) - { - FileVersion version; - version.SetProductVersion(0, 0); - EXPECT_EQ(_T("0.0.0.0"), version.GetProductVersionString()); - } - - TEST_F(FileVersionTest, getprodver_simple1) - { - FileVersion version; - version.SetProductVersion(1, 2); - EXPECT_EQ(_T("0.1.0.2"), version.GetProductVersionString()); - } - TEST_F(FileVersionTest, getprodver_real) - { - FileVersion version; - DWORD hi = (1 << 16) | 2; - DWORD lo = (3 << 16) | 4; - version.SetProductVersion(hi, lo); - EXPECT_EQ(_T("1.2.3.4"), version.GetProductVersionString()); - } - } // namespace