mirror of
https://github.com/Gnucash/gnucash.git
synced 2024-12-02 13:39:43 -06:00
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.
This commit is contained in:
parent
1eed3db5e7
commit
2b69278650
@ -425,11 +425,21 @@ std::string
|
|||||||
GncDateTimeImpl::format(const char* format) const
|
GncDateTimeImpl::format(const char* format) const
|
||||||
{
|
{
|
||||||
using Facet = boost::local_time::local_time_facet;
|
using Facet = boost::local_time::local_time_facet;
|
||||||
|
static std::locale cachedLocale;
|
||||||
|
static bool cachedLocaleAvailable = false;
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
|
||||||
|
if(!cachedLocaleAvailable)
|
||||||
|
{
|
||||||
|
cachedLocale = std::locale("");
|
||||||
|
cachedLocaleAvailable = true;
|
||||||
|
}
|
||||||
|
|
||||||
//The stream destructor frees the facet, so it must be heap-allocated.
|
//The stream destructor frees the facet, so it must be heap-allocated.
|
||||||
auto output_facet(new Facet(normalize_format(format).c_str()));
|
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.
|
// 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;
|
ss << m_time;
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user