diff options
author | Eike Rathke <erack@redhat.com> | 2013-09-20 21:46:12 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2013-09-20 21:46:43 +0200 |
commit | df0f34cb9c036f5cf69b72a740c1a8f2741ac966 (patch) | |
tree | 56ba724bc68ebefb28bb04402dc162820d661960 | |
parent | 677df250becd5cde71c6310f647e78ac3763347e (diff) |
trigger less conversions
Change-Id: Ie7ab85522b3ab0adb5bddd24b9db6affc10c4665
-rw-r--r-- | i18nlangtag/source/languagetag/languagetag.cxx | 54 | ||||
-rw-r--r-- | include/i18nlangtag/languagetag.hxx | 2 |
2 files changed, 49 insertions, 7 deletions
diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx index 01cd6d25d218..5779397f3309 100644 --- a/i18nlangtag/source/languagetag/languagetag.cxx +++ b/i18nlangtag/source/languagetag/languagetag.cxx @@ -611,7 +611,7 @@ LanguageTag::ImplPtr LanguageTagImpl::registerOnTheFly() pImpl = (*it).second; if (pImpl.get() != this) { - SAL_WARN( "i18nlangtag", "LanguageTag::registerOnTheFly: impl should be this"); + SAL_WARN( "i18nlangtag", "LanguageTag::registerOnTheFly: impl should be this for '" << maBcp47 << "'"); *pImpl = *this; // ensure consistency } } @@ -810,7 +810,10 @@ LanguageTag::ImplPtr LanguageTag::registerImpl() const LanguageTag::ImplPtr LanguageTag::getImpl() const { if (!mpImpl) + { mpImpl = registerImpl(); + syncVarsFromRawImpl(); + } return mpImpl; } @@ -1073,14 +1076,33 @@ void LanguageTag::syncFromImpl() SAL_INFO_IF( bRegister, "i18nlangtag", "LanguageTag::syncFromImpl: re-registering, '" << pImpl->maBcp47 << "' vs '" << maBcp47 << " and 0x" << ::std::hex << pImpl->mnLangID << " vs 0x" << ::std::hex << mnLangID); + syncVarsFromRawImpl(); + if (bRegister) + mpImpl = registerImpl(); +} + + +void LanguageTag::syncVarsFromImpl() const +{ + getImpl(); + syncVarsFromRawImpl(); +} + + +void LanguageTag::syncVarsFromRawImpl() const +{ + // Do not use getImpl() here. + LanguageTagImpl* pImpl = mpImpl.get(); + if (!pImpl) + return; + + // Obviously only mutable variables. mbInitializedBcp47 = pImpl->mbInitializedBcp47; maBcp47 = pImpl->maBcp47; mbInitializedLocale = pImpl->mbInitializedLocale; maLocale = pImpl->maLocale; mbInitializedLangID = pImpl->mbInitializedLangID; mnLangID = pImpl->mnLangID; - if (bRegister) - mpImpl = registerImpl(); } @@ -1304,6 +1326,8 @@ const OUString & LanguageTag::getBcp47( bool bResolveSystem ) const if (!bResolveSystem && mbSystemLocale) return theEmptyBcp47::get(); if (!mbInitializedBcp47) + syncVarsFromImpl(); + if (!mbInitializedBcp47) { getImpl()->getBcp47(); const_cast<LanguageTag*>(this)->syncFromImpl(); @@ -1436,6 +1460,8 @@ const com::sun::star::lang::Locale & LanguageTag::getLocale( bool bResolveSystem if (!bResolveSystem && mbSystemLocale) return theEmptyLocale::get(); if (!mbInitializedLocale) + syncVarsFromImpl(); + if (!mbInitializedLocale) { if (mbInitializedBcp47) const_cast<LanguageTag*>(this)->convertBcp47ToLocale(); @@ -1451,6 +1477,8 @@ LanguageType LanguageTag::getLanguageType( bool bResolveSystem ) const if (!bResolveSystem && mbSystemLocale) return LANGUAGE_SYSTEM; if (!mbInitializedLangID) + syncVarsFromImpl(); + if (!mbInitializedLangID) { if (mbInitializedBcp47) const_cast<LanguageTag*>(this)->convertBcp47ToLang(); @@ -1565,7 +1593,10 @@ OUString LanguageTagImpl::getLanguage() const OUString LanguageTag::getLanguage() const { - OUString aRet( getImpl()->getLanguage()); + ImplPtr pImpl = getImpl(); + if (pImpl->mbCachedLanguage) + return pImpl->maCachedLanguage; + OUString aRet( pImpl->getLanguage()); const_cast<LanguageTag*>(this)->syncFromImpl(); return aRet; } @@ -1584,7 +1615,10 @@ OUString LanguageTagImpl::getScript() const OUString LanguageTag::getScript() const { - OUString aRet( getImpl()->getScript()); + ImplPtr pImpl = getImpl(); + if (pImpl->mbCachedScript) + return pImpl->maCachedScript; + OUString aRet( pImpl->getScript()); const_cast<LanguageTag*>(this)->syncFromImpl(); return aRet; } @@ -1617,7 +1651,10 @@ OUString LanguageTagImpl::getCountry() const OUString LanguageTag::getCountry() const { - OUString aRet( getImpl()->getCountry()); + ImplPtr pImpl = getImpl(); + if (pImpl->mbCachedCountry) + return pImpl->maCachedCountry; + OUString aRet( pImpl->getCountry()); const_cast<LanguageTag*>(this)->syncFromImpl(); return aRet; } @@ -1650,7 +1687,10 @@ OUString LanguageTagImpl::getVariants() const OUString LanguageTag::getVariants() const { - OUString aRet( getImpl()->getVariants()); + ImplPtr pImpl = getImpl(); + if (pImpl->mbCachedVariants) + return pImpl->maCachedVariants; + OUString aRet( pImpl->getVariants()); const_cast<LanguageTag*>(this)->syncFromImpl(); return aRet; } diff --git a/include/i18nlangtag/languagetag.hxx b/include/i18nlangtag/languagetag.hxx index 27bcb34c2927..c8ee7177603a 100644 --- a/include/i18nlangtag/languagetag.hxx +++ b/include/i18nlangtag/languagetag.hxx @@ -504,6 +504,8 @@ private: ImplPtr getImpl() const; ImplPtr registerImpl() const; void syncFromImpl(); + void syncVarsFromRawImpl() const; + void syncVarsFromImpl() const; void convertLocaleToBcp47(); void convertLocaleToLang(); |