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 /unotools | |
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>
Diffstat (limited to 'unotools')
-rw-r--r-- | unotools/source/i18n/localedatawrapper.cxx | 36 |
1 files changed, 33 insertions, 3 deletions
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 |