mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Various performance fixes based on feedback
- const correctnes - avoid unnecessary copying - avoid need to reverse GList
This commit is contained in:
parent
2f7ed7f25d
commit
8b772384cd
@ -132,7 +132,7 @@ Gnucash::GnucashCli::start ([[maybe_unused]] int argc, [[maybe_unused]] char **a
|
||||
if (*m_quotes_cmd == "info")
|
||||
{
|
||||
auto quotes = gnc_get_quotes_instance();
|
||||
if (quotes.check())
|
||||
if (quotes.cmd_result() == 0)
|
||||
{
|
||||
std::cout << bl::format (bl::translate ("Found Finance::Quote version {1}.")) % quotes.version() << std::endl;
|
||||
std::cout << bl::translate ("Finance::Quote sources: ");
|
||||
|
@ -83,7 +83,7 @@ scm_add_quotes(void *data, [[maybe_unused]] int argc, [[maybe_unused]] char **ar
|
||||
qof_event_suspend();
|
||||
|
||||
auto quotes = gnc_get_quotes_instance();
|
||||
if (quotes.check())
|
||||
if (quotes.cmd_result() == 0)
|
||||
{
|
||||
std::cout << bl::format (bl::translate ("Found Finance::Quote version {1}.")) % quotes.version() << std::endl;
|
||||
auto quote_sources = quotes.sources_as_glist();
|
||||
|
@ -177,7 +177,7 @@ scm_run_gnucash (void *data, [[maybe_unused]] int argc, [[maybe_unused]] char **
|
||||
auto msg = bl::translate ("Checking Finance::Quote...").str(gnc_get_boost_locale());
|
||||
|
||||
auto quotes = gnc_get_quotes_instance();
|
||||
if (quotes.check())
|
||||
if (quotes.cmd_result() == 0)
|
||||
{
|
||||
msg = (bl::format (bl::translate("Found Finance::Quote version {1}.")) % quotes.version()).str(gnc_get_boost_locale());
|
||||
auto quote_sources = quotes.sources_as_glist();
|
||||
|
@ -55,9 +55,9 @@ GncQuotes::check (void)
|
||||
std::string stream_line;
|
||||
while (getline (out_stream, stream_line))
|
||||
if (m_version.empty())
|
||||
m_version = stream_line;
|
||||
std::swap (m_version, stream_line);
|
||||
else
|
||||
m_sources.push_back (stream_line);
|
||||
m_sources.push_back (std::move(stream_line));
|
||||
while (getline (err_stream, stream_line))
|
||||
m_error_msg.append(stream_line + "\n");
|
||||
|
||||
@ -76,15 +76,14 @@ GList*
|
||||
GncQuotes::sources_as_glist()
|
||||
{
|
||||
GList* slist = nullptr;
|
||||
for (auto source : m_sources)
|
||||
slist = g_list_append (slist, g_strdup(source.c_str()));
|
||||
std::for_each (m_sources.rbegin(), m_sources.rend(),
|
||||
[&slist](const std::string& source) { slist = g_list_prepend (slist, g_strdup(source.c_str())); });
|
||||
return slist;
|
||||
}
|
||||
|
||||
|
||||
|
||||
GncQuotes&
|
||||
gnc_get_quotes_instance (void)
|
||||
const GncQuotes& gnc_get_quotes_instance()
|
||||
{
|
||||
return quotes_cached;
|
||||
}
|
||||
|
@ -29,6 +29,10 @@ extern "C" {
|
||||
#include <glib.h>
|
||||
}
|
||||
|
||||
using QuoteSources = std::vector<std::string>;
|
||||
|
||||
const std::string not_found = std::string ("Not Found");
|
||||
|
||||
class GncQuotes
|
||||
{
|
||||
public:
|
||||
@ -38,18 +42,18 @@ public:
|
||||
GncQuotes() { check(); }
|
||||
|
||||
// Function to check if Finance::Quote is properly installed
|
||||
int cmd_result() { return m_cmd_result; }
|
||||
std::string error_msg() { return m_error_msg; }
|
||||
std::string version() { return m_version.empty() ? "Not Found" : m_version; }
|
||||
std::vector <std::string> sources() { return m_sources; }
|
||||
const int cmd_result() noexcept { return m_cmd_result; }
|
||||
const std::string& error_msg() noexcept { return m_error_msg; }
|
||||
const std::string& version() noexcept { return m_version.empty() ? not_found : m_version; }
|
||||
const QuoteSources& sources() noexcept { return m_sources; }
|
||||
GList* sources_as_glist ();
|
||||
private:
|
||||
std::string m_version;
|
||||
std::vector <std::string> m_sources;
|
||||
QuoteSources m_sources;
|
||||
int m_cmd_result;
|
||||
std::string m_error_msg;
|
||||
};
|
||||
|
||||
GncQuotes& gnc_get_quotes_instance (void);
|
||||
const GncQuotes& gnc_get_quotes_instance (void);
|
||||
|
||||
#endif /* GNC_QUOTES_HPP */
|
||||
|
Loading…
Reference in New Issue
Block a user