Browse Source

[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.
JINMEI Tatuya 12 years ago
parent
commit
0a15919f55
1 changed files with 6 additions and 10 deletions
  1. 6 10
      src/lib/datasrc/memory/domaintree.h

+ 6 - 10
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());
         }