summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2016-03-24 00:27:51 +0100
committerAndras Timar <andras.timar@collabora.com>2016-05-02 19:48:30 +0200
commit4a4839d93111b90dd1da95be74c35709e0a9a9a2 (patch)
treee6bc1ee4d5069f6ce1971417497a5ea99e1bedeb
parent292e525d287d97868b06f37732079128ae0ee2fa (diff)
don't allocate and destroy a LocaleDataItem for each cell, tdf#97989
Reviewed-on: https://gerrit.libreoffice.org/23480 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com> (cherry picked from commit 7da3a53958695bfb1405fa513f71beddc6c0ecb7) Change-Id: I8bcdc7a42c87d17fde1dc9c79bc361bb625f992b
-rw-r--r--include/unotools/localedatawrapper.hxx6
-rw-r--r--sc/source/core/data/column3.cxx2
-rw-r--r--unotools/source/i18n/localedatawrapper.cxx34
3 files changed, 39 insertions, 3 deletions
diff --git a/include/unotools/localedatawrapper.hxx b/include/unotools/localedatawrapper.hxx
index d6448599e596..f2e767561c0b 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;
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index c0376eab2d96..0c8ac2b030b9 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -1724,7 +1724,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 45c96bad4896..318e8235b62d 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(
@@ -159,15 +174,30 @@ void LocaleDataWrapper::invalidateData()
::com::sun::star::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 ::com::sun::star::i18n::LocaleDataItem();
+ static css::i18n::LocaleDataItem aEmptyItem;
+ return aEmptyItem;
}
::com::sun::star::uno::Sequence< ::com::sun::star::i18n::Currency2 > LocaleDataWrapper::getAllCurrencies() const