Skip to content

Commit

Permalink
Replace naked for loops with C++ algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
gjanssens committed Feb 16, 2024
1 parent b62c920 commit 48734e2
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions libgnucash/engine/gnc-commodity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,12 @@ gnc_quote_source_fq_version (void)
static QuoteSourceVec&
get_quote_source_from_type (QuoteSourceType type)
{
for (const auto& [s_type, sources] : quote_sources_map)
if (type == s_type)
return sources;

return new_quote_sources;
auto unknown_as_default = std::prev (quote_sources_map.end());
/* If none of the 'known' quote source vectors is found, return the unknown one by default */
auto quote_sources_it = std::find_if (quote_sources_map.begin(),
unknown_as_default,
[type] (const auto& qs) { return type == qs.first; });
return quote_sources_it->second;
}

/********************************************************************
Expand Down Expand Up @@ -387,11 +388,11 @@ gnc_quote_source_lookup_by_internal(const char * name)

for (const auto& [_, sources] : quote_sources_map)
{
for (const auto& source : sources)
{
if (g_strcmp0(name, source.get_internal_name()) == 0)
return (gnc_quote_source*)&source;
}
auto source_it = std::find_if (sources.begin(), sources.end(),
[name] (const auto& qs)
{ return (g_strcmp0(name, qs.get_internal_name()) == 0); });
if (source_it != sources.end())
return &(*source_it);
}

DEBUG("gnc_quote_source_lookup_by_internal: Unknown source %s", name);
Expand Down

0 comments on commit 48734e2

Please sign in to comment.