From 2b69278650f55b8ceed4eef9f4268a60138045a0 Mon Sep 17 00:00:00 2001 From: "Christopher D. Carson" Date: Tue, 1 Jan 2019 06:20:23 -0600 Subject: [PATCH] Re-coded for cached locale. Testing notes: Based on the averages of 3 runs, the net user CPU to save the XML file I use is: 10.2 seconds without this change 7.6 seconds with this change In my environment the first call to the format routine in question, the call that sets the cache value, is at the end of the XML load. --- libgnucash/engine/gnc-datetime.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libgnucash/engine/gnc-datetime.cpp b/libgnucash/engine/gnc-datetime.cpp index f5d99167ba..238be2db61 100644 --- a/libgnucash/engine/gnc-datetime.cpp +++ b/libgnucash/engine/gnc-datetime.cpp @@ -425,11 +425,21 @@ std::string GncDateTimeImpl::format(const char* format) const { using Facet = boost::local_time::local_time_facet; + static std::locale cachedLocale; + static bool cachedLocaleAvailable = false; std::stringstream ss; + + if(!cachedLocaleAvailable) + { + cachedLocale = std::locale(""); + cachedLocaleAvailable = true; + } + //The stream destructor frees the facet, so it must be heap-allocated. auto output_facet(new Facet(normalize_format(format).c_str())); // FIXME Rather than imbueing a locale below we probably should set std::locale::global appropriately somewhere. - ss.imbue(std::locale(std::locale(""), output_facet)); + // At that point the use of cachedLocale mechanism should be removed. + ss.imbue(std::locale(cachedLocale, output_facet)); ss << m_time; return ss.str(); }