[Libreoffice-commits] core.git: 7 commits - i18nlangtag/source include/i18nlangtag
Eike Rathke
erack at redhat.com
Sat Sep 21 06:25:07 PDT 2013
i18nlangtag/source/languagetag/languagetag.cxx | 116 +++++++++++++++++++++++--
include/i18nlangtag/languagetag.hxx | 19 +++-
2 files changed, 123 insertions(+), 12 deletions(-)
New commits:
commit dafd27829359201cab45462bae43baf19b369a14
Author: Eike Rathke <erack at redhat.com>
Date: Sat Sep 21 14:57:40 2013 +0200
register separate theSystemLocale for faster access
Change-Id: I0fc5938bd2c0157471539217806ad7844d765e8d
diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index 4a3ba4d..9ad4155 100644
--- a/i18nlangtag/source/languagetag/languagetag.cxx
+++ b/i18nlangtag/source/languagetag/languagetag.cxx
@@ -95,6 +95,7 @@ typedef ::std::map< LanguageType, LanguageTag::ImplPtr > MapLangID;
struct theMapBcp47 : public rtl::Static< MapBcp47, theMapBcp47 > {};
struct theMapLangID : public rtl::Static< MapLangID, theMapLangID > {};
struct theDontKnow : public rtl::Static< LanguageTag::ImplPtr, theDontKnow > {};
+struct theSystemLocale : public rtl::Static< LanguageTag::ImplPtr, theSystemLocale > {};
}
@@ -665,19 +666,49 @@ LanguageTag::ImplPtr LanguageTag::registerImpl() const
// methods as they may create temporary LanguageTag instances. Only
// LanguageTagImpl::convertToBcp47(Locale) is ok.
+ ImplPtr pImpl;
+
#if OSL_DEBUG_LEVEL > 0
- static size_t nAccesses = 0;
- ++nAccesses;
- SAL_INFO( "i18nlangtag", "LanguageTagImpl::registerImpl: " << nAccesses << " calls");
+ static size_t nCalls = 0;
+ ++nCalls;
+ SAL_INFO( "i18nlangtag", "LanguageTag::registerImpl: " << nCalls << " calls");
#endif
- ImplPtr pImpl;
+ // Do not register unresolved system locale, also force LangID if system
+ // and take the system locale shortcut if possible.
+ if (mbSystemLocale)
+ {
+ pImpl = theSystemLocale::get();
+ if (pImpl)
+ {
+#if OSL_DEBUG_LEVEL > 0
+ static size_t nCallsSystem = 0;
+ ++nCallsSystem;
+ SAL_INFO( "i18nlangtag", "LanguageTag::registerImpl: " << nCallsSystem << " system calls");
+#endif
+ return pImpl;
+ }
+ if (!mbInitializedLangID)
+ {
+ mnLangID = MsLangId::getRealLanguage( LANGUAGE_SYSTEM);
+ mbInitializedLangID = (mnLangID != LANGUAGE_SYSTEM);
+ SAL_WARN_IF( !mbInitializedLangID, "i18nlangtag", "LanguageTag::registerImpl: can't resolve system!");
+ }
+ }
- // Do not register unresolved system locale, also force LangID if system.
- if (mbSystemLocale && !mbInitializedLangID)
+ if (mbInitializedLangID)
{
- mnLangID = MsLangId::getRealLanguage( LANGUAGE_SYSTEM);
- mbInitializedLangID = true;
+ // A great share are calls for a system equal locale.
+ pImpl = theSystemLocale::get();
+ if (pImpl && pImpl->mnLangID == mnLangID)
+ {
+#if OSL_DEBUG_LEVEL > 0
+ static size_t nCallsSystemEqual = 0;
+ ++nCallsSystemEqual;
+ SAL_INFO( "i18nlangtag", "LanguageTag::registerImpl: " << nCallsSystemEqual << " system equal LangID calls");
+#endif
+ return pImpl;
+ }
}
// Force Bcp47 if not LangID.
@@ -687,6 +718,27 @@ LanguageTag::ImplPtr LanguageTag::registerImpl() const
mbInitializedBcp47 = !maBcp47.isEmpty();
}
+ if (mbInitializedBcp47)
+ {
+ // A great share are calls for a system equal locale.
+ pImpl = theSystemLocale::get();
+ if (pImpl && pImpl->maBcp47 == maBcp47)
+ {
+#if OSL_DEBUG_LEVEL > 0
+ static size_t nCallsSystemEqual = 0;
+ ++nCallsSystemEqual;
+ SAL_INFO( "i18nlangtag", "LanguageTag::registerImpl: " << nCallsSystemEqual << " system equal BCP47 calls");
+#endif
+ return pImpl;
+ }
+ }
+
+#if OSL_DEBUG_LEVEL > 0
+ static size_t nCallsNonSystem = 0;
+ ++nCallsNonSystem;
+ SAL_INFO( "i18nlangtag", "LanguageTag::registerImpl: " << nCallsNonSystem << " non-system calls");
+#endif
+
osl::MutexGuard aGuard( theMutex::get());
#if OSL_DEBUG_LEVEL > 0
@@ -820,12 +872,27 @@ LanguageTag::ImplPtr LanguageTag::registerImpl() const
if (!rDontKnow)
rDontKnow.reset( new LanguageTagImpl( *this));
pImpl = rDontKnow;
+#if OSL_DEBUG_LEVEL > 0
+ static size_t nCallsDontKnow = 0;
+ ++nCallsDontKnow;
+ SAL_INFO( "i18nlangtag", "LanguageTag::registerImpl: " << nCallsDontKnow << " DontKnow calls");
+#endif
}
else
{
SAL_WARN( "i18nlangtag", "LanguageTag::registerImpl: can't register for 0x" << ::std::hex << mnLangID );
pImpl.reset( new LanguageTagImpl( *this));
}
+
+ // If we reach here for mbSystemLocale we didn't have theSystemLocale
+ // above, so add it.
+ if (mbSystemLocale && mbInitializedLangID)
+ {
+ theSystemLocale::get() = pImpl;
+ SAL_INFO( "i18nlangtag", "LanguageTag::registerImpl: added system locale 0x"
+ << ::std::hex << pImpl->mnLangID << " '" << pImpl->maBcp47 << "'");
+ }
+
return pImpl;
}
commit 931e40703de0eec84ab53ea7450f937769cbc117
Author: Eike Rathke <erack at redhat.com>
Date: Sat Sep 21 12:41:49 2013 +0200
added registerImpl() debug counter
Change-Id: I84a79cbbbe06bdf1ae9e77d9cb5d429c6750fe21
diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index 5521697..4a3ba4d 100644
--- a/i18nlangtag/source/languagetag/languagetag.cxx
+++ b/i18nlangtag/source/languagetag/languagetag.cxx
@@ -665,6 +665,12 @@ LanguageTag::ImplPtr LanguageTag::registerImpl() const
// methods as they may create temporary LanguageTag instances. Only
// LanguageTagImpl::convertToBcp47(Locale) is ok.
+#if OSL_DEBUG_LEVEL > 0
+ static size_t nAccesses = 0;
+ ++nAccesses;
+ SAL_INFO( "i18nlangtag", "LanguageTagImpl::registerImpl: " << nAccesses << " calls");
+#endif
+
ImplPtr pImpl;
// Do not register unresolved system locale, also force LangID if system.
commit cf417c2cd421d21ccc780ea2cfde9c9339f6a878
Author: Eike Rathke <erack at redhat.com>
Date: Sat Sep 21 02:44:30 2013 +0200
use bcp47 unresolved system for operator<()
We have several tags mapping to one LangID, so using LangID isn't a good
idea.
Change-Id: I561745b032af7eb0c54cf55dbcd26872103e2e07
diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index 67047c61..5521697 100644
--- a/i18nlangtag/source/languagetag/languagetag.cxx
+++ b/i18nlangtag/source/languagetag/languagetag.cxx
@@ -2093,7 +2093,7 @@ bool LanguageTag::operator!=( const LanguageTag & rLanguageTag ) const
bool LanguageTag::operator<( const LanguageTag & rLanguageTag ) const
{
- return getLanguageType() < rLanguageTag.getLanguageType();
+ return getBcp47( false).compareToIgnoreAsciiCase( rLanguageTag.getBcp47( false)) < 0;
}
diff --git a/include/i18nlangtag/languagetag.hxx b/include/i18nlangtag/languagetag.hxx
index 7f06f92..7e282bb 100644
--- a/include/i18nlangtag/languagetag.hxx
+++ b/include/i18nlangtag/languagetag.hxx
@@ -399,9 +399,9 @@ public:
*/
bool operator!=( const LanguageTag & rLanguageTag ) const;
- /** Test this less than that.
+ /** Test this LanguageTag less than that LanguageTag.
- For sorted containers. Internally uses the LanguageType for comparison.
+ For sorted containers. Does NOT resolve system.
*/
bool operator<( const LanguageTag & rLanguageTag ) const;
commit 5799417f70fdee3291467c37c88d1bb0212187a2
Author: Eike Rathke <erack at redhat.com>
Date: Sat Sep 21 02:21:22 2013 +0200
added debug counter to getNextOnTheFlyLanguage()
Change-Id: If2c53309f50b67d9afeb097391f4d20637bee69c
diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index be6fa03..67047c61 100644
--- a/i18nlangtag/source/languagetag/languagetag.cxx
+++ b/i18nlangtag/source/languagetag/languagetag.cxx
@@ -123,6 +123,11 @@ static LanguageType getNextOnTheFlyLanguage()
}
}
}
+#if OSL_DEBUG_LEVEL > 0
+ static size_t nOnTheFlies = 0;
+ ++nOnTheFlies;
+ SAL_INFO( "i18nlangtag", "getNextOnTheFlyLanguage: number " << nOnTheFlies);
+#endif
return nOnTheFlyLanguage;
}
commit d1b8398c2f68f50550824cbb47fb188a3a818e62
Author: Eike Rathke <erack at redhat.com>
Date: Fri Sep 20 23:56:06 2013 +0200
added operator<() for sorted containers
Change-Id: Iffc3a41df21f2b95054f6f895c9848714ace1de0
diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index 054c7c3..be6fa03 100644
--- a/i18nlangtag/source/languagetag/languagetag.cxx
+++ b/i18nlangtag/source/languagetag/languagetag.cxx
@@ -2086,6 +2086,12 @@ bool LanguageTag::operator!=( const LanguageTag & rLanguageTag ) const
}
+bool LanguageTag::operator<( const LanguageTag & rLanguageTag ) const
+{
+ return getLanguageType() < rLanguageTag.getLanguageType();
+}
+
+
// static
LanguageTagImpl::Extraction LanguageTagImpl::simpleExtract( const OUString& rBcp47,
OUString& rLanguage, OUString& rScript, OUString& rCountry, OUString& rVariants )
diff --git a/include/i18nlangtag/languagetag.hxx b/include/i18nlangtag/languagetag.hxx
index b8a6347..7f06f92 100644
--- a/include/i18nlangtag/languagetag.hxx
+++ b/include/i18nlangtag/languagetag.hxx
@@ -399,6 +399,11 @@ public:
*/
bool operator!=( const LanguageTag & rLanguageTag ) const;
+ /** Test this less than that.
+
+ For sorted containers. Internally uses the LanguageType for comparison.
+ */
+ bool operator<( const LanguageTag & rLanguageTag ) const;
/** Convert MS-LangID to Locale.
commit 42dc3847ed7c3c3bcf43ffdb14eafeae17f79b7a
Author: Eike Rathke <erack at redhat.com>
Date: Fri Sep 20 23:22:39 2013 +0200
let reset() return a reference
Change-Id: I3700566e7ec2250909211a6d81c6f2a7854b463c
diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index 99611f1..054c7c3 100644
--- a/i18nlangtag/source/languagetag/languagetag.cxx
+++ b/i18nlangtag/source/languagetag/languagetag.cxx
@@ -844,7 +844,7 @@ void LanguageTag::resetVars()
}
-void LanguageTag::reset( const OUString & rBcp47LanguageTag, bool bCanonicalize )
+LanguageTag & LanguageTag::reset( const OUString & rBcp47LanguageTag, bool bCanonicalize )
{
resetVars();
maBcp47 = rBcp47LanguageTag;
@@ -858,31 +858,35 @@ void LanguageTag::reset( const OUString & rBcp47LanguageTag, bool bCanonicalize
// unconditional sync.
syncFromImpl();
}
+ return *this;
}
-void LanguageTag::reset( const com::sun::star::lang::Locale & rLocale )
+LanguageTag & LanguageTag::reset( const com::sun::star::lang::Locale & rLocale )
{
resetVars();
maLocale = rLocale;
mbSystemLocale = rLocale.Language.isEmpty();
mbInitializedLocale = !mbSystemLocale;
+ return *this;
}
-void LanguageTag::reset( LanguageType nLanguage )
+LanguageTag & LanguageTag::reset( LanguageType nLanguage )
{
resetVars();
mnLangID = nLanguage;
mbSystemLocale = nLanguage == LANGUAGE_SYSTEM;
mbInitializedLangID = !mbSystemLocale;
+ return *this;
}
-void LanguageTag::reset( const rtl_Locale & rLocale )
+LanguageTag & LanguageTag::reset( const rtl_Locale & rLocale )
{
reset( lang::Locale( rLocale.Language, rLocale.Country, rLocale.Variant));
convertFromRtlLocale();
+ return *this;
}
diff --git a/include/i18nlangtag/languagetag.hxx b/include/i18nlangtag/languagetag.hxx
index f8f9ae8..b8a6347 100644
--- a/include/i18nlangtag/languagetag.hxx
+++ b/include/i18nlangtag/languagetag.hxx
@@ -250,16 +250,16 @@ public:
/** Reset with existing BCP 47 language tag string. See ctor. */
- void reset( const OUString & rBcp47LanguageTag, bool bCanonicalize = false );
+ LanguageTag & reset( const OUString & rBcp47LanguageTag, bool bCanonicalize = false );
/** Reset with Locale. */
- void reset( const com::sun::star::lang::Locale & rLocale );
+ LanguageTag & reset( const com::sun::star::lang::Locale & rLocale );
/** Reset with LanguageType MS-LangID. */
- void reset( LanguageType nLanguage );
+ LanguageTag & reset( LanguageType nLanguage );
/** Reset with rtl_Locale. */
- void reset( const rtl_Locale & rLocale );
+ LanguageTag & reset( const rtl_Locale & rLocale );
/** Fall back to a known locale.
commit 3e70b51d214d69dcd92946ee1bfa6102626ddc51
Author: Eike Rathke <erack at redhat.com>
Date: Fri Sep 20 22:16:18 2013 +0200
added default ctor for maps etc.
sigh.. I hate to do this..
Change-Id: Icf5940c0e60d39a2a1a33fbf78d2af6deb729524
diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index 5779397..99611f1 100644
--- a/i18nlangtag/source/languagetag/languagetag.cxx
+++ b/i18nlangtag/source/languagetag/languagetag.cxx
@@ -487,6 +487,18 @@ LanguageTag::LanguageTag( LanguageType nLanguage )
}
+LanguageTag::LanguageTag()
+ :
+ mnLangID( LANGUAGE_DONTKNOW),
+ mbSystemLocale( false),
+ mbInitializedBcp47( false),
+ mbInitializedLocale( false),
+ mbInitializedLangID( false),
+ mbIsFallback( false)
+{
+}
+
+
LanguageTag::LanguageTag( const OUString& rBcp47, const OUString& rLanguage,
const OUString& rScript, const OUString& rCountry )
:
diff --git a/include/i18nlangtag/languagetag.hxx b/include/i18nlangtag/languagetag.hxx
index c8ee717..f8f9ae8 100644
--- a/include/i18nlangtag/languagetag.hxx
+++ b/include/i18nlangtag/languagetag.hxx
@@ -76,6 +76,12 @@ public:
/** Init LanguageTag with LanguageType MS-LangID. */
explicit LanguageTag( LanguageType nLanguage );
+ /** Default ctor, init LanguageTag with LanguageType LANGUAGE_DONTKNOW.
+
+ To be able to use LanguageTag in maps etc., avoid otherwise.
+ */
+ explicit LanguageTag();
+
/** Init LanguageTag with either BCP 47 language tag (precedence if not
empty), or a combination of language, script and country.
More information about the Libreoffice-commits
mailing list