diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2016-03-24 00:27:51 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2016-03-24 00:29:31 +0000 |
commit | 7da3a53958695bfb1405fa513f71beddc6c0ecb7 (patch) | |
tree | 8836744b4c60407d08961e628004c837bee258fd | |
parent | 013b7f6cb249fa08d00cb9124a1ab3429d72d6d2 (diff) |
don't allocate and destroy a LocaleDataItem for each cell, tdf#97989
Change-Id: I8bcdc7a42c87d17fde1dc9c79bc361bb625f992b
Reviewed-on: https://gerrit.libreoffice.org/23480
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
-rw-r--r-- | include/unotools/localedatawrapper.hxx | 8 | ||||
-rw-r--r-- | sc/source/core/data/column3.cxx | 2 | ||||
-rw-r--r-- | unotools/source/i18n/localedatawrapper.cxx | 36 |
3 files changed, 41 insertions, 5 deletions
diff --git a/include/unotools/localedatawrapper.hxx b/include/unotools/localedatawrapper.hxx index 9d99f516af70..419ac1517508 100644 --- a/include/unotools/localedatawrapper.hxx +++ b/include/unotools/localedatawrapper.hxx @@ -28,6 +28,7 @@ #include <unotools/readwritemutexguard.hxx> #include <unotools/unotoolsdllapi.h> #include <memory> +#include <map> namespace com { namespace sun { namespace star { namespace uno { @@ -74,6 +75,11 @@ class UNOTOOLS_DLLPUBLIC LocaleDataWrapper bool bLocaleDataItemValid; bool bReservedWordValid; mutable ::utl::ReadWriteMutex aMutex; + struct Locale_Compare + { + bool operator()(const css::lang::Locale& rLocale1, const css::lang::Locale& rLocale2) const; + }; + mutable std::map<css::lang::Locale, css::i18n::LocaleDataItem, Locale_Compare> maDataItemCache; // dummies, to be implemented or provided by XML locale data sal_Unicode cCurrZeroChar; @@ -137,7 +143,7 @@ public: // Wrapper implementations of service LocaleData css::i18n::LanguageCountryInfo getLanguageCountryInfo() const; - css::i18n::LocaleDataItem getLocaleItem() const; + const css::i18n::LocaleDataItem& getLocaleItem() const; /// NOTE: this wraps XLocaleData3::getAllCalendars2() in fact. css::uno::Sequence< css::i18n::Calendar2 > getAllCalendars() const; /// NOTE: this wraps XLocaleData2::getAllCurrencies2() in fact. diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index b350e4211aa4..a86cffe82322 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -1728,7 +1728,7 @@ bool ScColumn::ParseString( if (!pLocale) break; - LocaleDataItem aLocaleItem = pLocale->getLocaleItem(); + const LocaleDataItem& aLocaleItem = pLocale->getLocaleItem(); const OUString& rDecSep = aLocaleItem.decimalSeparator; const OUString& rGroupSep = aLocaleItem.thousandSeparator; if (rDecSep.getLength() != 1 || rGroupSep.getLength() != 1) diff --git a/unotools/source/i18n/localedatawrapper.cxx b/unotools/source/i18n/localedatawrapper.cxx index 76cae71cfe20..87a5140d6c88 100644 --- a/unotools/source/i18n/localedatawrapper.cxx +++ b/unotools/source/i18n/localedatawrapper.cxx @@ -63,6 +63,21 @@ namespace {}; } +bool LocaleDataWrapper::Locale_Compare::operator()(const css::lang::Locale& rLocale1, const css::lang::Locale& rLocale2) const +{ + if (rLocale1.Language < rLocale2.Language) + return true; + else if (rLocale1.Language > rLocale2.Language) + return false; + + if (rLocale1.Country < rLocale2.Country) + return true; + else if (rLocale1.Country > rLocale2.Country) + return false; + + return rLocale1.Variant < rLocale2.Variant; +} + sal_uInt8 LocaleDataWrapper::nLocaleDataChecking = 0; LocaleDataWrapper::LocaleDataWrapper( @@ -157,17 +172,32 @@ css::i18n::LanguageCountryInfo LocaleDataWrapper::getLanguageCountryInfo() const return css::i18n::LanguageCountryInfo(); } -css::i18n::LocaleDataItem LocaleDataWrapper::getLocaleItem() const +const css::i18n::LocaleDataItem& LocaleDataWrapper::getLocaleItem() const { + { + ::utl::ReadWriteGuard aGuard( aMutex ); + const css::lang::Locale& rLocal = getMyLocale(); + auto itr = maDataItemCache.find(rLocal); + if (itr != maDataItemCache.end()) + return itr->second; + } + try { - return xLD->getLocaleItem( getMyLocale() ); + ::utl::ReadWriteGuard aGuard( aMutex ); + + const css::lang::Locale& rLocal = getMyLocale(); + css::i18n::LocaleDataItem aItem = xLD->getLocaleItem( rLocal ); + auto aRet = maDataItemCache.insert(std::make_pair(rLocal, aItem)); + assert(aRet.second); + return aRet.first->second; } catch (const Exception& e) { SAL_WARN( "unotools.i18n", "getLocaleItem: Exception caught " << e.Message ); } - return css::i18n::LocaleDataItem(); + static css::i18n::LocaleDataItem aEmptyItem; + return aEmptyItem; } css::uno::Sequence< css::i18n::Currency2 > LocaleDataWrapper::getAllCurrencies() const |