tvg format: code refactoring #5
authorHermet Park <chuneon.park@samsung.com>
Tue, 20 Jul 2021 05:33:11 +0000 (14:33 +0900)
committerJunsuChoi <jsuya.choi@samsung.com>
Thu, 22 Jul 2021 08:24:22 +0000 (17:24 +0900)
replace from ofstream to FILE

We know both have the same purpose, we always prefer the less binary size.

So... this brings the binary size reduction.

1918496 => 1913528

src/lib/tvgSaverImpl.h

index 8a32f68..83ac025 100644 (file)
@@ -26,7 +26,7 @@
 #include "tvgBinaryDesc.h"
 #include <float.h>
 #include <math.h>
-#include <fstream>
+#include <stdio.h>
 
 struct Saver::Impl
 {
@@ -47,13 +47,14 @@ struct Saver::Impl
         return true;
     }
 
-    bool saveBufferToFile(const std::string& path)
+    bool bufferToFile(const std::string& path)
     {
-        ofstream outFile;
-        outFile.open(path, ios::out | ios::trunc | ios::binary);
-        if (!outFile.is_open()) return false;
-        outFile.write(buffer.data, buffer.count);
-        outFile.close();
+        FILE* fp = fopen(path.c_str(), "w+");
+        if (!fp) return false;
+
+        if (fwrite(buffer.data, sizeof(char), buffer.count, fp) == 0) return false;
+
+        fclose(fp);
 
         return true;
     }
@@ -405,7 +406,7 @@ struct Saver::Impl
 
         if (!writeHeader()) return false;
         if (serialize(paint) == 0) return false;
-        if (!saveBufferToFile(path)) return false;
+        if (!bufferToFile(path)) return false;
 
         return true;
     }