[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.3' - include/svl

Aron Budea aron.budea at collabora.com
Fri Jul 14 13:28:05 UTC 2017


 include/svl/ondemand.hxx |   54 +++++++++++++++++++++++++++--------------------
 1 file changed, 32 insertions(+), 22 deletions(-)

New commits:
commit a761ca485ebf24aaa57375f9e52ec883b3b99907
Author: Aron Budea <aron.budea at collabora.com>
Date:   Mon Jul 10 15:56:32 2017 +0200

    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.
    
    Reviewed-on: https://gerrit.libreoffice.org/39762
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>
    (cherry picked from commit 2a22696546ace75c38a72ad13f7383aedd00e06a)
    
    Change-Id: I3d64dbe8afa929cf416d87678762e82b45561d63
    Reviewed-on: https://gerrit.libreoffice.org/39906
    Reviewed-by: Andras Timar <andras.timar at collabora.com>
    Tested-by: Andras Timar <andras.timar at collabora.com>

diff --git a/include/svl/ondemand.hxx b/include/svl/ondemand.hxx
index 5019795e0173..8482040c2950 100644
--- a/include/svl/ondemand.hxx
+++ b/include/svl/ondemand.hxx
@@ -129,28 +129,29 @@ 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 CalendarWrapper*    pPtr;
-    mutable bool                bValid;
-            bool                bInitialized;
+    mutable css::lang::Locale  aLastAnyLocale;
+            std::unique_ptr<CalendarWrapper> pEnglishPtr;
+    mutable std::unique_ptr<CalendarWrapper> pAnyPtr;
 
 public:
                                 OnDemandCalendarWrapper()
-                                    : pPtr(nullptr)
-                                    , bValid(false)
-                                    , bInitialized(false)
-                                    {}
-                                ~OnDemandCalendarWrapper()
                                     {
-                                        delete pPtr;
+                                        LanguageTag aEnglishLanguageTag(LANGUAGE_ENGLISH_US);
+                                        aEnglishLocale = aEnglishLanguageTag.getLocale();
+                                        aLastAnyLocale = aEnglishLocale;
                                     }
 
             void                init(
@@ -160,28 +161,37 @@ public:
                                     {
                                         m_xContext = rxContext;
                                         changeLocale( rLocale );
-                                        if ( pPtr )
-                                        {
-                                            delete pPtr;
-                                            pPtr = nullptr;
-                                        }
-                                        bInitialized = true;
+                                        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 = new CalendarWrapper( m_xContext );
-                                            pPtr->loadDefaultCalendar( aLocale );
-                                            bValid = true;
+                                            pPtr = pEnglishPtr.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;
                                     }


More information about the Libreoffice-commits mailing list