gnucash stable: ensure boost::regex is compiled at startup
Christopher Lam
clam at code.gnucash.org
Thu May 28 05:07:51 EDT 2026
Updated via https://github.com/Gnucash/gnucash/commit/f3653213 (commit)
from https://github.com/Gnucash/gnucash/commit/2911a0cc (commit)
commit f36532131bc7628f50389fab5068b14c65498f55
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Wed May 27 22:41:20 2026 +0800
ensure boost::regex is compiled at startup
instead of per-call
diff --git a/gnucash/import-export/csv-imp/gnc-imp-props-price.cpp b/gnucash/import-export/csv-imp/gnc-imp-props-price.cpp
index 40b5529e7a..65f891fa02 100644
--- a/gnucash/import-export/csv-imp/gnc-imp-props-price.cpp
+++ b/gnucash/import-export/csv-imp/gnc-imp-props-price.cpp
@@ -68,7 +68,7 @@ GncNumeric parse_amount_price (const std::string &str, int currency_format)
if(!boost::regex_search(str, boost::regex("[0-9]")))
throw std::invalid_argument (_("Value doesn't appear to contain a valid number."));
- auto expr = boost::make_u32regex("[[:Sc:]]");
+ static const auto expr = boost::make_u32regex("[[:Sc:]]");
std::string str_no_symbols;
boost::u32regex_replace(icu::UnicodeString::fromUTF8(str), expr, "").toUTF8String(str_no_symbols);
diff --git a/gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp b/gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp
index 46d4b1bbb5..c53bf2fa33 100644
--- a/gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp
+++ b/gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp
@@ -138,7 +138,7 @@ GncNumeric parse_monetary (const std::string &str, int currency_format)
if(!boost::regex_search(str, boost::regex("[0-9]")))
throw std::invalid_argument (_("Value doesn't appear to contain a valid number."));
- auto expr = boost::make_u32regex("[[:Sc:][:blank:]]|--");
+ static const auto expr = boost::make_u32regex("[[:Sc:][:blank:]]|--");
std::string str_no_symbols;
boost::u32regex_replace(icu::UnicodeString::fromUTF8(str), expr, "").toUTF8String(str_no_symbols);
diff --git a/libgnucash/backend/dbi/gnc-backend-dbi.cpp b/libgnucash/backend/dbi/gnc-backend-dbi.cpp
index 15b5935148..08c0baa805 100644
--- a/libgnucash/backend/dbi/gnc-backend-dbi.cpp
+++ b/libgnucash/backend/dbi/gnc-backend-dbi.cpp
@@ -536,7 +536,7 @@ adjust_sql_options_string(const std::string& str)
/* Regex that finds the SQL_OPTION_TO_REMOVE as the first, last, or middle of a
* comma-delimited list.
*/
- boost::regex reg{"(?:," SQL_OPTION_TO_REMOVE "$|\\b"
+ static const boost::regex reg{"(?:," SQL_OPTION_TO_REMOVE "$|\\b"
SQL_OPTION_TO_REMOVE "\\b,?)"};
return regex_replace(str, reg, std::string{""});
}
diff --git a/libgnucash/engine/gnc-datetime.cpp b/libgnucash/engine/gnc-datetime.cpp
index 9c579071b1..fcfc5195a5 100644
--- a/libgnucash/engine/gnc-datetime.cpp
+++ b/libgnucash/engine/gnc-datetime.cpp
@@ -725,9 +725,8 @@ GncDateImpl::GncDateImpl(const std::string str, const std::string fmt) :
if (iter->m_re.empty())
throw std::invalid_argument ("No regex pattern available");
- boost::regex r(iter->m_re);
boost::smatch what;
- if(!boost::regex_search(str, what, r)) // regex didn't find a match
+ if(!boost::regex_search(str, what, iter->m_re)) // regex didn't find a match
throw std::invalid_argument (N_("Value can't be parsed into a date using the selected date format."));
// Bail out if a year was found with a yearless format specifier
diff --git a/libgnucash/engine/gnc-datetime.hpp b/libgnucash/engine/gnc-datetime.hpp
index 6c150a9222..1f146d3252 100644
--- a/libgnucash/engine/gnc-datetime.hpp
+++ b/libgnucash/engine/gnc-datetime.hpp
@@ -33,6 +33,7 @@
#include <optional>
#include <boost/date_time/gregorian/gregorian.hpp>
+#include <boost/regex.hpp>
typedef struct
{
@@ -187,7 +188,7 @@ public:
* themselves!
*/
GncDateFormat (const char* fmt, const char* re) :
- m_fmt(fmt), m_re(re) {}
+ m_fmt(fmt), m_re(re) {}
GncDateFormat (const char* fmt, StringToDate str_to_date, const char* re) :
m_fmt(fmt), m_re(re), m_str_to_date(str_to_date) {}
GncDateFormat (const char* fmt, StringToDate str_to_date) :
@@ -198,7 +199,7 @@ private:
/** Regular expression associated with the format string. This is to and
* only be used internally by the gnc-datetime code.
*/
- const std::string m_re;
+ boost::regex m_re;
std::optional<StringToDate> m_str_to_date;
friend class GncDateImpl;
Summary of changes:
gnucash/import-export/csv-imp/gnc-imp-props-price.cpp | 2 +-
gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp | 2 +-
libgnucash/backend/dbi/gnc-backend-dbi.cpp | 2 +-
libgnucash/engine/gnc-datetime.cpp | 3 +--
libgnucash/engine/gnc-datetime.hpp | 5 +++--
5 files changed, 7 insertions(+), 7 deletions(-)
More information about the gnucash-changes
mailing list