[Libreoffice-commits] .: i18npool/inc i18npool/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Nov 16 03:10:45 PST 2012


 i18npool/inc/i18npool/languagetag.hxx       |    4 +--
 i18npool/source/languagetag/languagetag.cxx |   32 ++++++++++++++++++----------
 2 files changed, 23 insertions(+), 13 deletions(-)

New commits:
commit 0d0c51d155dfc6a51a5da3c4d61ab6f40c5e0e5f
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Nov 16 12:07:53 2012 +0100

    return const reference for getBcp47() and getLocale()
    
    And use the rtl::Static pattern for statics.
    
    Change-Id: I80d8cc0a4a35771f86bec27edf41224d71cdea14

diff --git a/i18npool/inc/i18npool/languagetag.hxx b/i18npool/inc/i18npool/languagetag.hxx
index abc7ed1..aaf4ca3 100644
--- a/i18npool/inc/i18npool/languagetag.hxx
+++ b/i18npool/inc/i18npool/languagetag.hxx
@@ -68,7 +68,7 @@ public:
                locale to the real locale used.
                If FALSE, return an empty OUString for such a tag.
      */
-    rtl::OUString                   getBcp47( bool bResolveSystem = true ) const;
+    const rtl::OUString &           getBcp47( bool bResolveSystem = true ) const;
 
     /** Obtain language tag as Locale.
 
@@ -84,7 +84,7 @@ public:
                locale to the real locale used.
                If FALSE, return an empty Locale for such a tag.
      */
-    com::sun::star::lang::Locale    getLocale( bool bResolveSystem = true ) const;
+    const com::sun::star::lang::Locale &    getLocale( bool bResolveSystem = true ) const;
 
     /** Obtain mapping to MS-LangID.
 
diff --git a/i18npool/source/languagetag/languagetag.cxx b/i18npool/source/languagetag/languagetag.cxx
index 2b3dbc4..ad8b9c1 100644
--- a/i18npool/source/languagetag/languagetag.cxx
+++ b/i18npool/source/languagetag/languagetag.cxx
@@ -12,6 +12,7 @@
 #include <rtl/ustrbuf.hxx>
 #include <rtl/bootstrap.hxx>
 #include <osl/file.hxx>
+#include <rtl/instance.hxx>
 
 //#define erDEBUG
 
@@ -42,6 +43,13 @@ using namespace com::sun::star;
 #define ISO639_LANGUAGE_TAG "qlt"
 
 
+// "statics" to be returned as const reference to an empty locale and string.
+namespace {
+struct theEmptyLocale : public rtl::Static< lang::Locale, theEmptyLocale > {};
+struct theEmptyBcp47 : public rtl::Static< OUString, theEmptyBcp47 > {};
+}
+
+
 /** A reference holder for liblangtag data de/initialization, one static
     instance. Currently implemented such that the first "ref" inits and dtor
     (our library deinitialized) tears down.
@@ -71,7 +79,9 @@ private:
     void teardown();
 };
 
-static LiblantagDataRef theDataRef;
+namespace {
+struct theDataRef : public rtl::Static< LiblantagDataRef, theDataRef > {};
+}
 
 LiblantagDataRef::LiblantagDataRef()
     :
@@ -154,7 +164,7 @@ LanguageTag::LanguageTag( const rtl::OUString & rBcp47LanguageTag, bool bCanonic
         mbCachedScript( false),
         mbCachedCountry( false)
 {
-    theDataRef.incRef();
+    theDataRef::get().incRef();
 
     if (bCanonicalize)
         canonicalize();
@@ -177,7 +187,7 @@ LanguageTag::LanguageTag( const com::sun::star::lang::Locale & rLocale )
         mbCachedScript( false),
         mbCachedCountry( false)
 {
-    theDataRef.incRef();
+    theDataRef::get().incRef();
 }
 
 
@@ -196,7 +206,7 @@ LanguageTag::LanguageTag( LanguageType nLanguage )
         mbCachedScript( false),
         mbCachedCountry( false)
 {
-    theDataRef.incRef();
+    theDataRef::get().incRef();
 }
 
 
@@ -216,7 +226,7 @@ LanguageTag::LanguageTag( const rtl::OUString& rLanguage, const rtl::OUString& r
         mbCachedScript( false),
         mbCachedCountry( false)
 {
-    theDataRef.incRef();
+    theDataRef::get().incRef();
 }
 
 
@@ -241,7 +251,7 @@ LanguageTag::LanguageTag( const LanguageTag & rLanguageTag )
         mbCachedScript( rLanguageTag.mbCachedScript),
         mbCachedCountry( rLanguageTag.mbCachedCountry)
 {
-    theDataRef.incRef();
+    theDataRef::get().incRef();
 }
 
 
@@ -274,7 +284,7 @@ LanguageTag::~LanguageTag()
 {
     lt_tag_unref( MPLANGTAG);
 
-    theDataRef.decRef();
+    theDataRef::get().decRef();
 }
 
 
@@ -448,10 +458,10 @@ void LanguageTag::convertLangToBcp47()
 }
 
 
-rtl::OUString LanguageTag::getBcp47( bool bResolveSystem ) const
+const rtl::OUString & LanguageTag::getBcp47( bool bResolveSystem ) const
 {
     if (!bResolveSystem && mbSystemLocale)
-        return OUString();
+        return theEmptyBcp47::get();
     if (!mbInitializedBcp47)
     {
         if (mbInitializedLocale)
@@ -520,10 +530,10 @@ rtl::OUString LanguageTag::getRegionFromLangtag() const
 }
 
 
-com::sun::star::lang::Locale LanguageTag::getLocale( bool bResolveSystem ) const
+const com::sun::star::lang::Locale & LanguageTag::getLocale( bool bResolveSystem ) const
 {
     if (!bResolveSystem && mbSystemLocale)
-        return lang::Locale();
+        return theEmptyLocale::get();
     if (!mbInitializedLocale)
     {
         if (mbInitializedBcp47)


More information about the Libreoffice-commits mailing list