gnucash master: Multiple changes pushed
John Ralls
jralls at code.gnucash.org
Tue May 12 17:07:04 EDT 2020
Updated via https://github.com/Gnucash/gnucash/commit/1510f349 (commit)
via https://github.com/Gnucash/gnucash/commit/bd6840e0 (commit)
from https://github.com/Gnucash/gnucash/commit/57fe0515 (commit)
commit 1510f3492626922832220483e70487ea92e45c12
Author: John Ralls <jralls at ceridwen.us>
Date: Tue May 12 14:06:29 2020 -0700
Use std::unique_ptr instead of std::shared_ptr.
No need to share ownership.
diff --git a/libgnucash/engine/qoflog.cpp b/libgnucash/engine/qoflog.cpp
index e7848df92..89cc88a32 100644
--- a/libgnucash/engine/qoflog.cpp
+++ b/libgnucash/engine/qoflog.cpp
@@ -74,7 +74,8 @@ static QofLogModule log_module = "qof";
using StrVec = std::vector<std::string>;
struct ModuleEntry;
-using ModuleEntryPtr = std::shared_ptr<ModuleEntry>;
+using ModuleEntryPtr = std::unique_ptr<ModuleEntry>;
+using MEVec = std::vector<ModuleEntryPtr>;
static constexpr int parts = 4; //Log domain parts vector preallocation size
static constexpr QofLogLevel default_level = QOF_LOG_WARNING;
@@ -87,17 +88,17 @@ struct ModuleEntry
~ModuleEntry() = default;
std::string m_name;
QofLogLevel m_level;
- std::vector<ModuleEntryPtr> m_children;
+ MEVec m_children;
};
static ModuleEntryPtr _modules = NULL;
-static ModuleEntryPtr
+static ModuleEntry*
get_modules()
{
if (!_modules)
- _modules = std::make_shared<ModuleEntry>("", default_level);
- return _modules;
+ _modules = std::make_unique<ModuleEntry>("", default_level);
+ return _modules.get();
}
static StrVec
@@ -252,7 +253,7 @@ qof_log_init_filename(const gchar* log_filename)
fout = stderr;
if (previous_handler == NULL)
- previous_handler = g_log_set_default_handler(log4glib_handler, &_modules);
+ previous_handler = g_log_set_default_handler(log4glib_handler, modules);
if (warn_about_missing_permission)
{
@@ -299,18 +300,18 @@ qof_log_set_level(QofLogModule log_module, QofLogLevel level)
{
auto iter = std::find_if(module->m_children.begin(),
module->m_children.end(),
- [part](ModuleEntryPtr child){
+ [part](auto& child){
return child && part == child->m_name;
});
if (iter == module->m_children.end())
{
- auto child = std::make_shared<ModuleEntry>(part, default_level);
- module->m_children.push_back(child);
- module = child;
+ auto child = std::make_unique<ModuleEntry>(part, default_level);
+ module->m_children.emplace_back(std::move(child));
+ module = module->m_children.back().get();
}
else
{
- module = *iter;
+ module = iter->get();
}
}
module->m_level = level;
@@ -343,7 +344,7 @@ qof_log_check(QofLogModule domain, QofLogLevel level)
{
auto iter = std::find_if(module->m_children.begin(),
module->m_children.end(),
- [part](ModuleEntryPtr child) {
+ [part](auto& child) {
return child && part == child->m_name; });
if (iter == module->m_children.end())
@@ -352,7 +353,7 @@ qof_log_check(QofLogModule domain, QofLogLevel level)
if (level <= (*iter)->m_level)
return TRUE;
- module = *iter;
+ module = iter->get();
}
return FALSE;
}
commit bd6840e035c2d9b3a928c938b82af3b857e7ca76
Author: John Ralls <jralls at ceridwen.us>
Date: Tue May 12 12:00:09 2020 -0700
Fix incorrecly logging all possible messages regardless of log level.
diff --git a/libgnucash/engine/qoflog.cpp b/libgnucash/engine/qoflog.cpp
index 71bcfb097..e7848df92 100644
--- a/libgnucash/engine/qoflog.cpp
+++ b/libgnucash/engine/qoflog.cpp
@@ -76,10 +76,14 @@ using StrVec = std::vector<std::string>;
struct ModuleEntry;
using ModuleEntryPtr = std::shared_ptr<ModuleEntry>;
+static constexpr int parts = 4; //Log domain parts vector preallocation size
+static constexpr QofLogLevel default_level = QOF_LOG_WARNING;
struct ModuleEntry
{
- ModuleEntry(std::string name) :
- m_name{name}, m_level{QOF_LOG_WARNING}, m_children{4} {}
+ ModuleEntry(std::string name, QofLogLevel level) :
+ m_name{name}, m_level{level} {
+ m_children.reserve(parts);
+ }
~ModuleEntry() = default;
std::string m_name;
QofLogLevel m_level;
@@ -92,29 +96,33 @@ static ModuleEntryPtr
get_modules()
{
if (!_modules)
- {
- _modules = std::make_shared<ModuleEntry>("");
- _modules->m_level = QOF_LOG_WARNING;
- }
+ _modules = std::make_shared<ModuleEntry>("", default_level);
return _modules;
}
static StrVec
split_domain (const std::string domain)
{
- static constexpr int parts = 4; //enough room for most cases
- std::vector<std::string> domain_parts{4};
+ StrVec domain_parts;
+ domain_parts.reserve(parts);
int start = 0;
auto pos = domain.find(".");
if (pos == std::string::npos)
+ {
domain_parts.emplace_back(domain);
+ }
else
+ {
while (pos != std::string::npos)
{
- domain_parts.emplace_back(domain.substr(start, pos));
+ auto part_name{domain.substr(start, pos - start)};
+ domain_parts.emplace_back(part_name);
start = pos + 1;
pos = domain.find(".", start);
}
+ auto part_name{domain.substr(start, pos)};
+ domain_parts.emplace_back(part_name);
+ }
return domain_parts;
}
@@ -296,7 +304,7 @@ qof_log_set_level(QofLogModule log_module, QofLogLevel level)
});
if (iter == module->m_children.end())
{
- auto child = std::make_shared<ModuleEntry>(part);
+ auto child = std::make_shared<ModuleEntry>(part, default_level);
module->m_children.push_back(child);
module = child;
}
@@ -324,11 +332,11 @@ qof_log_check(QofLogModule domain, QofLogLevel level)
PWARN("0 is not a valid log level");
return FALSE;
}
-
auto module = get_modules();
// If the level is < the default then no need to look further.
if (level < module->m_level)
return TRUE;
+
auto domain_vec = split_domain(domain);
for (auto part : domain_vec)
@@ -337,8 +345,13 @@ qof_log_check(QofLogModule domain, QofLogLevel level)
module->m_children.end(),
[part](ModuleEntryPtr child) {
return child && part == child->m_name; });
- if (iter == module->m_children.end()) return FALSE;
- if (level <= (*iter)->m_level) return TRUE;
+
+ if (iter == module->m_children.end())
+ return FALSE;
+
+ if (level <= (*iter)->m_level)
+ return TRUE;
+
module = *iter;
}
return FALSE;
Summary of changes:
libgnucash/engine/qoflog.cpp | 62 +++++++++++++++++++++++++++-----------------
1 file changed, 38 insertions(+), 24 deletions(-)
More information about the gnucash-changes
mailing list