summaryrefslogtreecommitdiff
path: root/include/svl/ondemand.hxx
diff options
context:
space:
mode:
authorAron Budea <aron.budea@collabora.com>2017-07-10 15:56:32 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-07-11 14:01:21 +0200
commit2a22696546ace75c38a72ad13f7383aedd00e06a (patch)
tree714ae3ccbb683cdf95d7831072399bec530d44d2 /include/svl/ondemand.hxx
parent65e4a776e8315fd61fd67ad00d28985b11f0b79e (diff)
tdf#109045: store en calendar separately in OnDemandCalendarWrapper
When working with pivot cache there's alternating use of locale dependent and locale indepentent formats, which causes unnecessary loading of calendars due to constant switching. OnDemandLocaleDataWrapper already does this, now do something similar in OnDemandCalendarWrapper. Change-Id: I3d64dbe8afa929cf416d87678762e82b45561d63 Reviewed-on: https://gerrit.libreoffice.org/39762 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include/svl/ondemand.hxx')
-rw-r--r--include/svl/ondemand.hxx50
1 files changed, 35 insertions, 15 deletions
diff --git a/include/svl/ondemand.hxx b/include/svl/ondemand.hxx
index d1c0815dc16c..81fb6e36e5fd 100644
--- a/include/svl/ondemand.hxx
+++ b/include/svl/ondemand.hxx
@@ -129,24 +129,30 @@ public:
const LocaleDataWrapper& operator*() const { return *get(); }
};
-/** Load a calendar only if it's needed.
+/** Load a calendar only if it's needed. Keep calendar for "en" locale
+ separately, as there can be alternation between locale dependent and
+ locale independent formats.
SvNumberformatter uses it upon switching locales.
+
@ATTENTION If the default ctor is used the init() method MUST be called
before accessing the calendar.
*/
class OnDemandCalendarWrapper
{
css::uno::Reference< css::uno::XComponentContext > m_xContext;
+ css::lang::Locale aEnglishLocale;
css::lang::Locale aLocale;
- mutable std::unique_ptr<CalendarWrapper>
- pPtr;
- mutable bool bValid;
+ mutable css::lang::Locale aLastAnyLocale;
+ std::unique_ptr<CalendarWrapper> pEnglishPtr;
+ mutable std::unique_ptr<CalendarWrapper> pAnyPtr;
public:
OnDemandCalendarWrapper()
- : pPtr(nullptr)
- , bValid(false)
- {}
+ {
+ LanguageTag aEnglishLanguageTag(LANGUAGE_ENGLISH_US);
+ aEnglishLocale = aEnglishLanguageTag.getLocale();
+ aLastAnyLocale = aEnglishLocale;
+ }
void init(
const css::uno::Reference< css::uno::XComponentContext >& rxContext,
@@ -155,25 +161,39 @@ public:
{
m_xContext = rxContext;
changeLocale( rLocale );
- pPtr.reset();
+ pEnglishPtr.reset(new CalendarWrapper( m_xContext ));
+ pEnglishPtr->loadDefaultCalendar( aEnglishLocale );
+ pAnyPtr.reset();
}
void changeLocale( const css::lang::Locale& rLocale )
{
- bValid = false;
aLocale = rLocale;
}
CalendarWrapper* get() const
{
- if ( !bValid )
+ CalendarWrapper* pPtr;
+ if ( aLocale == aEnglishLocale )
{
- if ( !pPtr )
- pPtr.reset(new CalendarWrapper( m_xContext ));
- pPtr->loadDefaultCalendar( aLocale );
- bValid = true;
+ pPtr = pEnglishPtr.get();
}
- return pPtr.get();
+ else
+ {
+ if ( !pAnyPtr )
+ {
+ pAnyPtr.reset(new CalendarWrapper( m_xContext ));
+ pAnyPtr->loadDefaultCalendar(aLocale);
+ aLastAnyLocale = aLocale;
+ }
+ else if ( aLocale != aLastAnyLocale )
+ {
+ pAnyPtr->loadDefaultCalendar( aLocale );
+ aLastAnyLocale = aLocale;
+ }
+ pPtr = pAnyPtr.get();
+ }
+ return pPtr;
}
};