[SCM] exiv2 packaging branch, master, updated. debian/0.25-3.1-3734-gdcbc29a

Maximiliano Curia maxy at moszumanska.debian.org
Thu Jul 13 17:37:16 UTC 2017


Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/exiv2.git;a=commitdiff;h=57fa6c9

The following commit has been merged in the master branch:
commit 57fa6c9211c0b87efb990ec35ed6d8b0209bab58
Author: Andreas Huggel <ahuggel at gmx.net>
Date:   Sat Oct 8 11:36:48 2005 +0000

    Changed MemIo "copy-on-expand" to "copy-on-write" strategy to ensure that the original buffer is never modified
---
 src/basicio.cpp | 34 +++++++++++++++++-----------------
 src/basicio.hpp | 20 +++++++++++---------
 2 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/src/basicio.cpp b/src/basicio.cpp
index 29c9519..9702a3e 100644
--- a/src/basicio.cpp
+++ b/src/basicio.cpp
@@ -362,27 +362,25 @@ namespace Exiv2 {
         return BasicIo::AutoPtr(new MemIo);
     }
 
-    void MemIo::checkSize(long wcount)
+    void MemIo::reserve(long wcount)
     {
         long need = wcount + idx_;
+
+        if (!isMalloced_) {
+            // Minimum size for 1st block is 32kB
+            long size  = std::max(32768 * (1 + need / 32768), size_);
+            byte* data = (byte*)std::malloc(size);
+            std::memcpy(data, data_, size_);
+            data_ = data;
+            sizeAlloced_ = size;
+            isMalloced_ = true;
+        }
+
         if (need > size_) {
             if (need > sizeAlloced_) {
                 // Allocate in blocks of 32kB
                 long want = 32768 * (1 + need / 32768);
-                if (size_ > 0) {
-                    if (!isMalloced_) {
-                        // "copy-on-expand"
-                        byte* data = (byte*)std::malloc(want);
-                        memcpy(data, data_, size_);
-                        data_ = data;
-                    }
-                    else {
-                        data_ = (byte*)std::realloc(data_, want);
-                    }
-                }
-                else {
-                    data_ = (byte*)std::malloc(want);
-                }
+                data_ = (byte*)std::realloc(data_, want);
                 sizeAlloced_ = want;
                 isMalloced_ = true;
             }
@@ -392,7 +390,8 @@ namespace Exiv2 {
 
     long MemIo::write(const byte* data, long wcount)
     {
-        checkSize(wcount);
+        reserve(wcount);
+        assert(isMalloced_);
         memcpy(&data_[idx_], data, wcount);
         idx_ += wcount;
         return wcount;
@@ -445,7 +444,8 @@ namespace Exiv2 {
 
     int MemIo::putb(byte data)
     {
-        checkSize(1);
+        reserve(1);
+        assert(isMalloced_);
         data_[idx_++] = data;
         return data;
     }
diff --git a/src/basicio.hpp b/src/basicio.hpp
index 9ea2d6b..3cceeb0 100644
--- a/src/basicio.hpp
+++ b/src/basicio.hpp
@@ -458,11 +458,12 @@ namespace Exiv2 {
     }; // class FileIo
 
     /*!
-      @brief Provides binary IO on blocks of memory by implementing the
-          BasicIo interface. The current implementation makes a copy of
-          any data passed to its constructors. If writes are performed, the
-          changed data can be retrieved using the read methods (since the
-          data used in construction is never modified).
+      @brief Provides binary IO on blocks of memory by implementing the BasicIo
+          interface. A copy-on-write implementation ensures that the data passed
+          in is only copied when necessary, i.e., as soon as data is written to
+          the MemIo. The original data is only used for reading. If writes are
+          performed, the changed data can be retrieved using the read methods
+          (since the data used in construction is never modified).
 
       @note If read only usage of this class is common, it might be worth
           creating a specialized readonly class or changing this one to
@@ -476,8 +477,9 @@ namespace Exiv2 {
         //! Default constructor that results in an empty object
         MemIo();
         /*!
-          @brief Constructor that accepts a block of memory to be copied.
-              IO operations are performed on the copied memory.
+          @brief Constructor that accepts a block of memory. A copy-on-write
+              algorithm allows read operations directly from the original data
+              and will create a copy of the buffer on the first write operation.
           @param data Pointer to data. Data must be at least \em size
               bytes long
           @param size Number of bytes to copy.
@@ -563,7 +565,7 @@ namespace Exiv2 {
          */
         virtual int getb();
         /*!
-          @brief Clear the memory clock and then transfer data from
+          @brief Clear the memory block and then transfer data from
               the \em src BasicIo object into a new block of memory.
 
           This method is optimized to simply swap memory block if the source
@@ -633,7 +635,7 @@ namespace Exiv2 {
         bool isMalloced_;               //!< Was the buffer allocated?
 
         // METHODS
-        void checkSize(long wcount);
+        void reserve(long wcount);
     }; // class MemIo
 }                                       // namespace Exiv2
 

-- 
exiv2 packaging



More information about the pkg-kde-commits mailing list