Author: wyoung
Date: Sat Aug 11 00:14:59 2007
New Revision: 1748

URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1748&view=rev
Log:
Extracted ColData::dec_ref_count() method from repeated code for
decrementing the internal buffer's reference count and deallocating it
if necessary.

Modified:
    trunk/lib/coldata.cpp
    trunk/lib/coldata.h

Modified: trunk/lib/coldata.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/coldata.cpp?rev=1748&r1=1747&r2=1748&view=diff
==============================================================================
--- trunk/lib/coldata.cpp (original)
+++ trunk/lib/coldata.cpp Sat Aug 11 00:14:59 2007
@@ -33,9 +33,7 @@
 
 ColData::~ColData()
 {
-       if (buffer_ && (--buffer_->refs_ == 0)) {
-               delete buffer_;
-       }
+       dec_ref_count();
 }
 
 

Modified: trunk/lib/coldata.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/coldata.h?rev=1748&r1=1747&r2=1748&view=diff
==============================================================================
--- trunk/lib/coldata.h (original)
+++ trunk/lib/coldata.h Sat Aug 11 00:14:59 2007
@@ -252,9 +252,7 @@
        /// the pointer.
        ColData& operator =(const char* str)
        {
-               if (buffer_ && (--buffer_->refs_ == 0)) {
-                       delete buffer_;
-               }
+               dec_ref_count();
 
                buffer_ = new Buffer(str, strlen(str),
                                mysql_type_info::string_type, false);
@@ -269,9 +267,7 @@
        /// deep copy, assign a string to this object instead.
        ColData& operator =(const ColData& cd)
        {
-               if (buffer_ && (--buffer_->refs_ == 0)) {
-                       delete buffer_;
-               }
+               dec_ref_count();
 
                buffer_ = cd.buffer_;
                ++buffer_->refs_;
@@ -348,6 +344,17 @@
        template <class T, class B> operator Null<T, B>() const;
 
 private:
+       /// \brief Decrement the buffer's reference count
+       ///
+       /// Called by dtor and by operator=()s before replacing the buffer's
+       /// contents.  If ref count falls to 0, deallocates the buffer.
+       void dec_ref_count()
+       {
+               if (buffer_ && (--buffer_->refs_ == 0)) {
+                       delete buffer_;
+               }
+       }
+       
        /// \brief Holds a ColData object's internal reference-counted
        /// string buffer.
        class Buffer {


_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits

Reply via email to