[Libreoffice-commits] core.git: 2 commits - i18nlangtag/source

Stephan Bergmann sbergman at redhat.com
Wed May 20 01:19:57 PDT 2015


 i18nlangtag/source/languagetag/languagetag.cxx |   58 +++++++++----------------
 1 file changed, 23 insertions(+), 35 deletions(-)

New commits:
commit 8baaf76ae373a7c945e1cc2fa5cd57b59749d414
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed May 20 10:18:32 2015 +0200

    teardown is only called from ~LiblangtagDataRef, anyway
    
    ...so don't obscure that sad reality
    
    Change-Id: I0ddd572e55d66f6c23c776ca62885b6ba482bf5e

diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index 4102554..34a7f71 100644
--- a/i18nlangtag/source/languagetag/languagetag.cxx
+++ b/i18nlangtag/source/languagetag/languagetag.cxx
@@ -159,19 +159,14 @@ class LiblangtagDataRef
 public:
     LiblangtagDataRef();
     ~LiblangtagDataRef();
-    inline void incRef()
+    inline void init()
     {
-        if (mnRef != SAL_MAX_UINT32 && !mnRef++)
+        if (!mbInitialized)
             setup();
     }
-    inline void decRef()
-    {
-        if (mnRef != SAL_MAX_UINT32 && mnRef && !--mnRef)
-            teardown();
-    }
 private:
     OString maDataPath;   // path to liblangtag data, "|" if system
-    sal_uInt32   mnRef;
+    bool mbInitialized;
 
     void setupDataPath();
     void setup();
@@ -184,16 +179,14 @@ struct theDataRef : public rtl::Static< LiblangtagDataRef, theDataRef > {};
 
 LiblangtagDataRef::LiblangtagDataRef()
     :
-        mnRef(0)
+        mbInitialized(false)
 {
 }
 
 LiblangtagDataRef::~LiblangtagDataRef()
 {
-    // When destructed we're tearing down unconditionally.
-    if (mnRef)
-        mnRef = 1;
-    decRef();
+    if (mbInitialized)
+        teardown();
 }
 
 void LiblangtagDataRef::setup()
@@ -202,8 +195,7 @@ void LiblangtagDataRef::setup()
     if (maDataPath.isEmpty())
         setupDataPath();
     lt_db_initialize();
-    // Hold ref eternally.
-    mnRef = SAL_MAX_UINT32;
+    mbInitialized = true;
 }
 
 void LiblangtagDataRef::teardown()
@@ -420,7 +412,7 @@ LanguageTagImpl::LanguageTagImpl( const LanguageTagImpl & rLanguageTagImpl )
         mbCachedVariants( rLanguageTagImpl.mbCachedVariants)
 {
     if (mpImplLangtag)
-        theDataRef::get().incRef();
+        theDataRef::get().init();
 }
 
 
@@ -453,9 +445,7 @@ LanguageTagImpl& LanguageTagImpl::operator=( const LanguageTagImpl & rLanguageTa
     mbCachedCountry     = rLanguageTagImpl.mbCachedCountry;
     mbCachedVariants    = rLanguageTagImpl.mbCachedVariants;
     if (mpImplLangtag && !oldTag)
-        theDataRef::get().incRef();
-    else if (!mpImplLangtag && oldTag)
-        theDataRef::get().decRef();
+        theDataRef::get().init();
     return *this;
 }
 
@@ -465,7 +455,6 @@ LanguageTagImpl::~LanguageTagImpl()
     if (mpImplLangtag)
     {
         lt_tag_unref( mpImplLangtag);
-        theDataRef::get().decRef();
     }
 }
 
@@ -1203,7 +1192,7 @@ bool LanguageTagImpl::canonicalize()
 
     if (!mpImplLangtag)
     {
-        theDataRef::get().incRef();
+        theDataRef::get().init();
         mpImplLangtag = lt_tag_new();
     }
 
@@ -1491,7 +1480,7 @@ void LanguageTag::convertFromRtlLocale()
          * string. */
 #if 0
         myLtError aError;
-        theDataRef::get().incRef();
+        theDataRef::get().init();
         mpImplLangtag = lt_tag_convert_from_locale( aStr.getStr(), &aError.p);
         maBcp47 = OStringToOUString( lt_tag_get_string( mpImplLangtag), RTL_TEXTENCODING_UTF8);
         mbInitializedBcp47 = true;
@@ -2703,13 +2692,12 @@ bool LanguageTag::isValidBcp47( const OUString& rString, OUString* o_pCanonicali
         lt_tag_t* mpLangtag;
         guard()
         {
-            theDataRef::get().incRef();
+            theDataRef::get().init();
             mpLangtag = lt_tag_new();
         }
         ~guard()
         {
             lt_tag_unref( mpLangtag);
-            theDataRef::get().decRef();
         }
     } aVar;
 
commit f387b04dc89d2bab96d77a6f1445d272e2b1d827
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed May 20 09:46:17 2015 +0200

    typo
    
    Change-Id: Ic6869491940482e866ec8e803ded89752746ab73

diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index c5366f7..4102554 100644
--- a/i18nlangtag/source/languagetag/languagetag.cxx
+++ b/i18nlangtag/source/languagetag/languagetag.cxx
@@ -154,11 +154,11 @@ bool LanguageTag::isOnTheFlyID( LanguageType nLang )
     instance. Currently implemented such that the first "ref" inits and dtor
     (our library deinitialized) tears down.
 */
-class LiblantagDataRef
+class LiblangtagDataRef
 {
 public:
-    LiblantagDataRef();
-    ~LiblantagDataRef();
+    LiblangtagDataRef();
+    ~LiblangtagDataRef();
     inline void incRef()
     {
         if (mnRef != SAL_MAX_UINT32 && !mnRef++)
@@ -179,16 +179,16 @@ private:
 };
 
 namespace {
-struct theDataRef : public rtl::Static< LiblantagDataRef, theDataRef > {};
+struct theDataRef : public rtl::Static< LiblangtagDataRef, theDataRef > {};
 }
 
-LiblantagDataRef::LiblantagDataRef()
+LiblangtagDataRef::LiblangtagDataRef()
     :
         mnRef(0)
 {
 }
 
-LiblantagDataRef::~LiblantagDataRef()
+LiblangtagDataRef::~LiblangtagDataRef()
 {
     // When destructed we're tearing down unconditionally.
     if (mnRef)
@@ -196,9 +196,9 @@ LiblantagDataRef::~LiblantagDataRef()
     decRef();
 }
 
-void LiblantagDataRef::setup()
+void LiblangtagDataRef::setup()
 {
-    SAL_INFO( "i18nlangtag", "LiblantagDataRef::setup: initializing database");
+    SAL_INFO( "i18nlangtag", "LiblangtagDataRef::setup: initializing database");
     if (maDataPath.isEmpty())
         setupDataPath();
     lt_db_initialize();
@@ -206,13 +206,13 @@ void LiblantagDataRef::setup()
     mnRef = SAL_MAX_UINT32;
 }
 
-void LiblantagDataRef::teardown()
+void LiblangtagDataRef::teardown()
 {
-    SAL_INFO( "i18nlangtag", "LiblantagDataRef::teardown: finalizing database");
+    SAL_INFO( "i18nlangtag", "LiblangtagDataRef::teardown: finalizing database");
     lt_db_finalize();
 }
 
-void LiblantagDataRef::setupDataPath()
+void LiblangtagDataRef::setupDataPath()
 {
     // maDataPath is assumed to be empty here.
     OUString aURL("$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER "/liblangtag");


More information about the Libreoffice-commits mailing list