OSDN Git Service

* Reduce memory usage while comparing folders
authorsdottaka <none@none>
Mon, 30 Dec 2013 06:28:00 +0000 (15:28 +0900)
committersdottaka <none@none>
Mon, 30 Dec 2013 06:28:00 +0000 (15:28 +0900)
 (remove unused member variables)
* Remove DiffFileFlags class and move DiffFileFlags::ToString() to FileFlags class

--HG--
branch : stable

14 files changed:
Src/Common/UniFile.cpp
Src/Common/UniFile.h
Src/Common/unicoder.h
Src/CompareEngines/ByteComparator.cpp
Src/DiffFileInfo.cpp
Src/DiffFileInfo.h
Src/DirItem.cpp
Src/DirItem.h
Src/DirTravel.cpp
Src/DirViewColItems.cpp
Src/FileTextStats.h
Src/FileVersion.cpp
Src/FileVersion.h
Testing/GoogleTest/FileVersion/FileVersion_test.cpp

index c12391a..2c1d8f9 100644 (file)
@@ -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;
 }
 
 /**
index 7580332..b29db83 100644 (file)
@@ -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;
 };
index de632e2..eb8d931 100644 (file)
@@ -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. */
index 401cd64..0ad1eaf 100644 (file)
@@ -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')
                {
index fb456c0..1e9e6e7 100644 (file)
 #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()
index fcb4895..7ca01cb 100644 (file)
 #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 */
 
index ce0290d..5bd0032 100644 (file)
 #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();
 }
index 9ab7e91..f95d209 100644 (file)
@@ -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);
index e5c0315..f9db1cd 100644 (file)
@@ -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..
index 5cc06f9..a7749a2 100644 (file)
@@ -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<const DiffFileFlags *>(p);
+       const FileFlags &r = *static_cast<const FileFlags *>(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<const DiffFileFlags *>(p);
-       const DiffFileFlags &s = *static_cast<const DiffFileFlags *>(q);
+       const FileFlags &r = *static_cast<const FileFlags *>(p);
+       const FileFlags &s = *static_cast<const FileFlags *>(q);
        return r.ToString() == s.ToString();
 }
 
index 4a9aaf7..da39e06 100644 (file)
@@ -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; }
 };
 
 
index ac4e7bc..cbcb6f9 100644 (file)
  * @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));
-}
index b14aecc..147fb8d 100644 (file)
 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_
index b2e2273..c636f11 100644 (file)
@@ -51,11 +51,6 @@ namespace
                FileVersion version;\r
                EXPECT_EQ(_T(""), version.GetFileVersionString());\r
        }\r
-       TEST_F(FileVersionTest, getprodver_notset)\r
-       {\r
-               FileVersion version;\r
-               EXPECT_EQ(_T("0.0.0.0"), version.GetProductVersionString());\r
-       }\r
 \r
        TEST_F(FileVersionTest, getfilever_zeros)\r
        {\r
@@ -79,26 +74,4 @@ namespace
                EXPECT_EQ(_T("1.2.3.4"), version.GetFileVersionString());\r
        }\r
        \r
-       TEST_F(FileVersionTest, getprodver_zeros)\r
-       {\r
-               FileVersion version;\r
-               version.SetProductVersion(0, 0);\r
-               EXPECT_EQ(_T("0.0.0.0"), version.GetProductVersionString());\r
-       }\r
-\r
-       TEST_F(FileVersionTest, getprodver_simple1)\r
-       {\r
-               FileVersion version;\r
-               version.SetProductVersion(1, 2);\r
-               EXPECT_EQ(_T("0.1.0.2"), version.GetProductVersionString());\r
-       }\r
-       TEST_F(FileVersionTest, getprodver_real)\r
-       {\r
-               FileVersion version;\r
-               DWORD hi = (1 << 16) | 2;\r
-               DWORD lo = (3 << 16) | 4;\r
-               version.SetProductVersion(hi, lo);\r
-               EXPECT_EQ(_T("1.2.3.4"), version.GetProductVersionString());\r
-       }\r
-\r
 }  // namespace\r