[Libreoffice-commits] core.git: Branch 'libreoffice-6-2' - i18nlangtag/source

Eike Rathke (via logerrit) logerrit at kemper.freedesktop.org
Thu Oct 3 09:01:39 UTC 2019


 i18nlangtag/source/languagetag/languagetag.cxx |   30 ++++++++++++++++---------
 1 file changed, 20 insertions(+), 10 deletions(-)

New commits:
commit e7b8101cf7643d612393079d7f1cea07d8b1c774
Author:     Eike Rathke <erack at redhat.com>
AuthorDate: Fri Sep 27 22:35:13 2019 +0200
Commit:     Xisco FaulĂ­ <xiscofauli at libreoffice.org>
CommitDate: Thu Oct 3 11:00:43 2019 +0200

    Resolves: tdf#127786 cache Glibc locale string in LanguageTagImpl
    
    ... for non-simple @modifier strings that are constructed using
    liblangtag, as loading resource strings needs it over and over and
    over again.
    
    Change-Id: Ib6a74e5ddb44508aa41f101c200a508bfa4a13bd
    Reviewed-on: https://gerrit.libreoffice.org/79770
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Jenkins
    (cherry picked from commit 24c7c12224f1c1d66f335f6fe085595352137646)
    Reviewed-on: https://gerrit.libreoffice.org/79775
    Reviewed-by: Xisco FaulĂ­ <xiscofauli at libreoffice.org>
    (cherry picked from commit 99782b52c3cc25a32661c382ca98a32f6ec87003)
    Reviewed-on: https://gerrit.libreoffice.org/79787

diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index c0e27492f912..ef34402d02de 100644
--- a/i18nlangtag/source/languagetag/languagetag.cxx
+++ b/i18nlangtag/source/languagetag/languagetag.cxx
@@ -252,11 +252,12 @@ private:
 
     mutable css::lang::Locale               maLocale;
     mutable OUString                        maBcp47;
-    mutable OUString                        maCachedLanguage;   ///< cache getLanguage()
-    mutable OUString                        maCachedScript;     ///< cache getScript()
-    mutable OUString                        maCachedCountry;    ///< cache getCountry()
-    mutable OUString                        maCachedVariants;   ///< cache getVariants()
-    mutable lt_tag_t*                       mpImplLangtag;      ///< liblangtag pointer
+    mutable OUString                        maCachedLanguage;    ///< cache getLanguage()
+    mutable OUString                        maCachedScript;      ///< cache getScript()
+    mutable OUString                        maCachedCountry;     ///< cache getCountry()
+    mutable OUString                        maCachedVariants;    ///< cache getVariants()
+    mutable OUString                        maCachedGlibcString; ///< cache getGlibcLocaleString()
+    mutable lt_tag_t*                       mpImplLangtag;       ///< liblangtag pointer
     mutable LanguageType                    mnLangID;
     mutable LanguageTag::ScriptType         meScriptType;
     mutable Decision                        meIsValid;
@@ -271,6 +272,7 @@ private:
     mutable bool                            mbCachedScript      : 1;
     mutable bool                            mbCachedCountry     : 1;
     mutable bool                            mbCachedVariants    : 1;
+    mutable bool                            mbCachedGlibcString : 1;
 
     OUString const &    getBcp47() const;
     OUString const &    getLanguage() const;
@@ -384,7 +386,8 @@ LanguageTagImpl::LanguageTagImpl( const LanguageTag & rLanguageTag )
         mbCachedLanguage( false),
         mbCachedScript( false),
         mbCachedCountry( false),
-        mbCachedVariants( false)
+        mbCachedVariants( false),
+        mbCachedGlibcString( false)
 {
 }
 
@@ -397,6 +400,7 @@ LanguageTagImpl::LanguageTagImpl( const LanguageTagImpl & rLanguageTagImpl )
         maCachedScript( rLanguageTagImpl.maCachedScript),
         maCachedCountry( rLanguageTagImpl.maCachedCountry),
         maCachedVariants( rLanguageTagImpl.maCachedVariants),
+        maCachedGlibcString( rLanguageTagImpl.maCachedGlibcString),
         mpImplLangtag( rLanguageTagImpl.mpImplLangtag ?
                 lt_tag_copy( rLanguageTagImpl.mpImplLangtag) : nullptr),
         mnLangID( rLanguageTagImpl.mnLangID),
@@ -412,7 +416,8 @@ LanguageTagImpl::LanguageTagImpl( const LanguageTagImpl & rLanguageTagImpl )
         mbCachedLanguage( rLanguageTagImpl.mbCachedLanguage),
         mbCachedScript( rLanguageTagImpl.mbCachedScript),
         mbCachedCountry( rLanguageTagImpl.mbCachedCountry),
-        mbCachedVariants( rLanguageTagImpl.mbCachedVariants)
+        mbCachedVariants( rLanguageTagImpl.mbCachedVariants),
+        mbCachedGlibcString( rLanguageTagImpl.mbCachedGlibcString)
 {
     if (mpImplLangtag)
         theDataRef::get().init();
@@ -430,6 +435,7 @@ LanguageTagImpl& LanguageTagImpl::operator=( const LanguageTagImpl & rLanguageTa
     maCachedScript      = rLanguageTagImpl.maCachedScript;
     maCachedCountry     = rLanguageTagImpl.maCachedCountry;
     maCachedVariants    = rLanguageTagImpl.maCachedVariants;
+    maCachedGlibcString = rLanguageTagImpl.maCachedGlibcString;
     lt_tag_t * oldTag = mpImplLangtag;
     mpImplLangtag       = rLanguageTagImpl.mpImplLangtag ?
                             lt_tag_copy( rLanguageTagImpl.mpImplLangtag) : nullptr;
@@ -448,6 +454,7 @@ LanguageTagImpl& LanguageTagImpl::operator=( const LanguageTagImpl & rLanguageTa
     mbCachedScript      = rLanguageTagImpl.mbCachedScript;
     mbCachedCountry     = rLanguageTagImpl.mbCachedCountry;
     mbCachedVariants    = rLanguageTagImpl.mbCachedVariants;
+    mbCachedGlibcString = rLanguageTagImpl.mbCachedGlibcString;
     if (mpImplLangtag && !oldTag)
         theDataRef::get().init();
     return *this;
@@ -1902,7 +1909,9 @@ OUString LanguageTag::getVariants() const
 
 OUString LanguageTagImpl::getGlibcLocaleString() const
 {
-    OUString sLocale;
+    if (mbCachedGlibcString)
+        return maCachedGlibcString;
+
     if (!mpImplLangtag)
     {
         meIsLiblangtagNeeded = DECISION_YES;
@@ -1913,11 +1922,12 @@ OUString LanguageTagImpl::getGlibcLocaleString() const
         char* pLang = lt_tag_convert_to_locale(mpImplLangtag, nullptr);
         if (pLang)
         {
-            sLocale = OUString::createFromAscii( pLang);
+            maCachedGlibcString = OUString::createFromAscii( pLang);
+            mbCachedGlibcString = true;
             free(pLang);
         }
     }
-    return sLocale;
+    return maCachedGlibcString;
 }
 
 OUString LanguageTag::getGlibcLocaleString( const OUString & rEncoding ) const


More information about the Libreoffice-commits mailing list