Skip to content

Commit

Permalink
[account.cpp] don't use GValue in kvp getters
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherlam committed Oct 6, 2024
1 parent 2f2cf6a commit 773afbb
Showing 1 changed file with 22 additions and 38 deletions.
60 changes: 22 additions & 38 deletions libgnucash/engine/Account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char*>() : nullptr;
}

static void
Expand Down Expand Up @@ -2561,27 +2558,17 @@ static std::optional<gnc_numeric>
get_kvp_gnc_numeric_path (const Account *acc, const std::vector<std::string>& 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<gnc_numeric*>(g_value_get_boxed (&v));
auto rv = gnc_numeric_check (*val) ? std::nullopt : std::make_optional<gnc_numeric>(*val);
g_value_unset (&v);
return rv;
if (auto slot{QOF_INSTANCE(acc)->kvp_data->get_slot(path)})
return *slot->get_ptr<gnc_numeric>();
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<GncGUID*>(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<GncGUID*>(), gnc_account_get_book (acc)) : nullptr;
}

static void
Expand All @@ -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<int64_t>() != 0;
case KvpValueImpl::Type::STRING:
return g_strcmp0 (slot->get<const char*>(), "true") == 0;
default:
return false;
}
}

void
Expand Down Expand Up @@ -4091,13 +4078,10 @@ static const std::optional<gint64>
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<gint64> 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<int64_t>();

return {};
}

gint64
Expand Down

0 comments on commit 773afbb

Please sign in to comment.