From df0f34cb9c036f5cf69b72a740c1a8f2741ac966 Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Fri, 20 Sep 2013 21:46:12 +0200 Subject: trigger less conversions Change-Id: Ie7ab85522b3ab0adb5bddd24b9db6affc10c4665 --- i18nlangtag/source/languagetag/languagetag.cxx | 54 ++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 7 deletions(-) (limited to 'i18nlangtag/source') 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(); } @@ -1303,6 +1325,8 @@ const OUString & LanguageTag::getBcp47( bool bResolveSystem ) const { if (!bResolveSystem && mbSystemLocale) return theEmptyBcp47::get(); + if (!mbInitializedBcp47) + syncVarsFromImpl(); if (!mbInitializedBcp47) { getImpl()->getBcp47(); @@ -1435,6 +1459,8 @@ const com::sun::star::lang::Locale & LanguageTag::getLocale( bool bResolveSystem { if (!bResolveSystem && mbSystemLocale) return theEmptyLocale::get(); + if (!mbInitializedLocale) + syncVarsFromImpl(); if (!mbInitializedLocale) { if (mbInitializedBcp47) @@ -1450,6 +1476,8 @@ LanguageType LanguageTag::getLanguageType( bool bResolveSystem ) const { if (!bResolveSystem && mbSystemLocale) return LANGUAGE_SYSTEM; + if (!mbInitializedLangID) + syncVarsFromImpl(); if (!mbInitializedLangID) { if (mbInitializedBcp47) @@ -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(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(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(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(this)->syncFromImpl(); return aRet; } -- cgit