diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp index b45f6352e39..af031911c80 100644 --- a/libgnucash/engine/Account.cpp +++ b/libgnucash/engine/Account.cpp @@ -2529,11 +2529,8 @@ static const char* get_kvp_string_path (const Account *acc, const StrVec& path) { g_return_val_if_fail (GNC_IS_ACCOUNT(acc), nullptr); - GValue v = G_VALUE_INIT; - qof_instance_get_path_kvp (QOF_INSTANCE (acc), &v, path); - const char* rv = G_VALUE_HOLDS_STRING (&v) ? g_value_get_string (&v) : nullptr; - g_value_unset (&v); - return rv; + auto slot{QOF_INSTANCE(acc)->kvp_data->get_slot(path)}; + return slot ? slot->get() : nullptr; } static void @@ -2561,27 +2558,17 @@ static std::optional get_kvp_gnc_numeric_path (const Account *acc, const std::vector& path) { g_return_val_if_fail (acc, std::nullopt); - GValue v = G_VALUE_INIT; - qof_instance_get_path_kvp (QOF_INSTANCE (acc), &v, path); - if (!G_VALUE_HOLDS_BOXED (&v)) return std::nullopt; - auto val = static_cast(g_value_get_boxed (&v)); - auto rv = gnc_numeric_check (*val) ? std::nullopt : std::make_optional(*val); - g_value_unset (&v); - return rv; + if (auto slot{QOF_INSTANCE(acc)->kvp_data->get_slot(path)}) + return *slot->get_ptr(); + return {}; } static Account* get_kvp_account_path (const Account *acc, const StrVec& path) { g_return_val_if_fail (GNC_IS_ACCOUNT(acc), nullptr); - - GValue v = G_VALUE_INIT; - qof_instance_get_path_kvp (QOF_INSTANCE (acc), &v, path); - - auto guid = static_cast(G_VALUE_HOLDS_BOXED (&v) ? g_value_get_boxed(&v) : nullptr); - g_value_unset (&v); - - return guid ? xaccAccountLookup (guid, gnc_account_get_book (acc)) : nullptr; + auto slot{QOF_INSTANCE(acc)->kvp_data->get_slot(path)}; + return slot ? xaccAccountLookup (slot->get(), gnc_account_get_book (acc)) : nullptr; } static void @@ -2602,18 +2589,18 @@ set_kvp_boolean_path (Account *acc, const StrVec& path, gboolean option) static gboolean get_kvp_boolean_path (const Account *acc, const StrVec& path) { - GValue v = G_VALUE_INIT; - gboolean retval = FALSE; g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE); - qof_instance_get_path_kvp (QOF_INSTANCE(acc), &v, path); - if (G_VALUE_HOLDS_INT64 (&v)) - retval = (g_value_get_int64 (&v) != 0); - if (G_VALUE_HOLDS_BOOLEAN (&v)) - retval = (g_value_get_boolean (&v)); - if (G_VALUE_HOLDS_STRING (&v)) - retval = !strcmp (g_value_get_string (&v), "true"); - g_value_unset (&v); - return retval; + auto slot{QOF_INSTANCE(acc)->kvp_data->get_slot(path)}; + if (!slot) return false; + switch (slot->get_type()) + { + case KvpValueImpl::Type::INT64: + return slot->get() != 0; + case KvpValueImpl::Type::STRING: + return g_strcmp0 (slot->get(), "true") == 0; + default: + return false; + } } void @@ -4091,13 +4078,10 @@ static const std::optional get_kvp_int64_path (const Account *acc, const StrVec& path) { g_return_val_if_fail (GNC_IS_ACCOUNT(acc), std::nullopt); - GValue v = G_VALUE_INIT; - std::optional rv; - qof_instance_get_path_kvp (QOF_INSTANCE (acc), &v, path); - if (G_VALUE_HOLDS_INT64 (&v)) - rv = g_value_get_int64 (&v); - g_value_unset (&v); - return rv; + if (auto slot{QOF_INSTANCE(acc)->kvp_data->get_slot(path)}) + return slot->get(); + + return {}; } gint64