From 35aeed45ec4b8c1246dbec71de36e5a2136ece07 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Thu, 16 Mar 2023 22:08:10 +0100 Subject: [PATCH] [engine] Remove two replace functions from KvpValue These were not used outside a test. And that test was not leak free, as a result of the functions not doing what they are supposed to do when the current value is not of the type that is expected. (NULL is returned, but the value is not replaced) --- libgnucash/engine/kvp-value.cpp | 20 -------------------- libgnucash/engine/kvp-value.hpp | 16 ---------------- libgnucash/engine/test/test-kvp-value.cpp | 13 ------------- 3 files changed, 49 deletions(-) diff --git a/libgnucash/engine/kvp-value.cpp b/libgnucash/engine/kvp-value.cpp index 456138a39a..ac3329016f 100644 --- a/libgnucash/engine/kvp-value.cpp +++ b/libgnucash/engine/kvp-value.cpp @@ -99,26 +99,6 @@ KvpValueImpl::get_type() const noexcept return KvpValue::Type::INVALID; } -KvpFrame * -KvpValueImpl::replace_frame_nc (KvpFrame * new_value) noexcept -{ - if (datastore.type() != type_id()) - return {}; - auto ret = boost::get(datastore); - datastore = new_value; - return ret; -} - -GList * -KvpValueImpl::replace_glist_nc (GList * new_value) noexcept -{ - if (datastore.type() != type_id()) - return {}; - auto ret = boost::get(datastore); - datastore = new_value; - return ret; -} - struct to_string_visitor : boost::static_visitor { std::ostringstream & output; diff --git a/libgnucash/engine/kvp-value.hpp b/libgnucash/engine/kvp-value.hpp index ea2f2003b9..b61f98911c 100644 --- a/libgnucash/engine/kvp-value.hpp +++ b/libgnucash/engine/kvp-value.hpp @@ -100,22 +100,6 @@ struct KvpValueImpl */ ~KvpValueImpl() noexcept; - /** - * Replaces the frame within this KvpValueImpl. - * - * If this KvpValueImpl doesn't contain a KvpFrame, nullptr - * is returned. Otherwise, the old KvpFrame * is returned. - */ - KvpFrame * replace_frame_nc (KvpFrame *) noexcept; - - /** - * Replaces the glist within this KvpValueImpl. - * - * If this KvpValueImpl doesn't contain a GList, nullptr - * is returned. Otherwise, the old GList * is returned. - */ - GList * replace_glist_nc (GList *) noexcept; - /** * Adds another value to this KvpValueImpl. * diff --git a/libgnucash/engine/test/test-kvp-value.cpp b/libgnucash/engine/test/test-kvp-value.cpp index b4b8772b67..7cf67b0c6b 100644 --- a/libgnucash/engine/test/test-kvp-value.cpp +++ b/libgnucash/engine/test/test-kvp-value.cpp @@ -30,19 +30,6 @@ #include #include -TEST (KvpValueTest, Replace_Frame) -{ - auto f1 = new KvpFrameImpl; - std::unique_ptr v1 {new KvpValueImpl {f1}}; - auto f2 = new KvpFrameImpl; - EXPECT_EQ (f1, v1->replace_frame_nc (f2)); - v1->set (5.2); - /*f1 and f2 should be deleted now*/ - f1 = new KvpFrameImpl; - EXPECT_EQ (nullptr, v1->replace_frame_nc (f1)); - delete f1; -} - TEST (KvpValueTest, Equality) { std::unique_ptr v1 {new KvpValueImpl { (int64_t)1}};