[gexiv2/wip/phako/gio: 26/27] gio: Skip one allocation



commit 0210c519c009dae7876bac0b8519da1f7d04af60
Author: Jens Georg <mail jensge org>
Date:   Sat Dec 29 18:33:29 2018 +0100

    gio: Skip one allocation

 gexiv2/gexiv2-metadata.cpp | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
---
diff --git a/gexiv2/gexiv2-metadata.cpp b/gexiv2/gexiv2-metadata.cpp
index 683c82d..a2f422d 100644
--- a/gexiv2/gexiv2-metadata.cpp
+++ b/gexiv2/gexiv2-metadata.cpp
@@ -47,17 +47,13 @@ public:
     int putb(Exiv2::byte data) { return EOF; }
 
     Exiv2::DataBuf read(long rcount) {
-        Exiv2::DataBuf b;
-        Exiv2::byte *buf = new Exiv2::byte[rcount];
+        Exiv2::DataBuf b{rcount};
 
-        long bytes_read = this->read(buf, rcount);
-        if (bytes_read > 0) {
-            b.alloc(bytes_read);
-            memcpy(b.pData_, buf, bytes_read);
+        long bytes_read = this->read(b.pData_, rcount);
+        if (bytes_read > 0 && bytes_read != rcount) {
+            b.reset(std::pair<Exiv2::byte*, long>(b.pData_, bytes_read));
         }
 
-        delete[] buf;
-
         return b;
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]