[Libreoffice-commits] core.git: include/unotools sc/source unotools/source
Markus Mohrhard
markus.mohrhard at googlemail.com
Thu Mar 24 00:30:01 UTC 2016
include/unotools/localedatawrapper.hxx | 8 +++++-
sc/source/core/data/column3.cxx | 2 -
unotools/source/i18n/localedatawrapper.cxx | 36 ++++++++++++++++++++++++++---
3 files changed, 41 insertions(+), 5 deletions(-)
New commits:
commit 7da3a53958695bfb1405fa513f71beddc6c0ecb7
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Thu Mar 24 00:27:51 2016 +0100
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 at libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
diff --git a/include/unotools/localedatawrapper.hxx b/include/unotools/localedatawrapper.hxx
index 9d99f51..419ac15 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 b350e42..a86cffe 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 76cae71..87a5140 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
More information about the Libreoffice-commits
mailing list