OSDN Git Service

Slightly improve comparison time for large files
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Wed, 15 Mar 2023 13:05:04 +0000 (22:05 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Wed, 15 Mar 2023 13:05:04 +0000 (22:05 +0900)
Src/Common/UniFile.cpp
Src/Common/UniFile.h
Src/DiffTextBuffer.cpp

index 2ed860b..589a02f 100644 (file)
@@ -753,6 +753,13 @@ bool UniStdioFile::DoOpen(const String& filename, const String& mode)
        return true;
 }
 
+bool UniStdioFile::SetVBuf(int mode, size_t size)
+{
+       if (!IsOpen())
+               return false;
+       return setvbuf(m_fp, NULL, mode, size) == 0;
+}
+
 /** @brief Record a custom error */
 void UniStdioFile::LastErrorCustom(const String& desc)
 {
index ae4f11b..5e7bdcf 100644 (file)
@@ -9,6 +9,7 @@
 #pragma once
 
 #include "unicoder.h"
+#include <cstdio>
 
 namespace Poco { class SharedMemory; }
 
@@ -254,6 +255,7 @@ public:
        virtual bool OpenCreate(const String& filename);
        virtual bool OpenCreateUtf8(const String& filename);
        virtual bool Open(const String& filename, const String& mode);
+       virtual bool SetVBuf(int mode, size_t size);
        void Close() override;
 
        virtual bool IsOpen() const override;
index 4c1778f..1b77fcc 100644 (file)
@@ -471,6 +471,8 @@ int CDiffTextBuffer::SaveToFile (const String& pszFileName,
                return SAVE_FAILED;
        }
 
+       const size_t StdioBufSize = (std::min)(512 * 1024, BUFSIZ + nLines * 32);
+       file.SetVBuf(_IOFBF, StdioBufSize);
        file.WriteBom();
 
        // line loop : get each real line and write it in the file