From: JINMEI Tatuya Date: Thu, 9 Aug 2012 00:56:16 +0000 (-0700) Subject: [2100] (not directly related) cleanup: always destroy old data in setData(). X-Git-Tag: trac2351_base~115^2~3^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0a15919f5570c67cc6cfee64fbbb83732098cd51;p=thirdparty%2Fkea.git [2100] (not directly related) cleanup: always destroy old data in setData(). actually the previous implementation seems buggy; it returns the given pionter, not the old data. Worse, this code path isn't tested. It's a typical example of YAGNI; if we don't see the need for it, don't do it; if you cannot regist the temptation of making it smarter, at least you should write tests. At least ZoneTable doesn't need it, so I chose to clean it up. If and when we find it necessary, we should implementation from the scratch, and test-driven. --- diff --git a/src/lib/datasrc/memory/domaintree.h b/src/lib/datasrc/memory/domaintree.h index cca348cf72..33efc88082 100644 --- a/src/lib/datasrc/memory/domaintree.h +++ b/src/lib/datasrc/memory/domaintree.h @@ -245,19 +245,15 @@ public: /// \name Setter functions. //@{ - /// \brief Set the data stored in the node. If there is old data, it - /// is either returned or destroyed based on what is passed in \c - /// old_data. + /// \brief Set the data stored in the node. + /// + /// Any old data is destroyed. + /// /// \param mem_sgmt The \c MemorySegment that allocated memory for /// the node data. /// \param data The new data to set. - /// \param old_data If \c NULL is passed here, any old data is - /// destroyed. Otherwise, the old data is returned - /// in this location. - void setData(util::MemorySegment& mem_sgmt, T* data, T** old_data = NULL) { - if (old_data != NULL) { - *old_data = data; - } else { + void setData(util::MemorySegment& mem_sgmt, T* data) { + if (data_) { const DT deleter; deleter(mem_sgmt, data_.get()); }