From dac29c278531d5474289eb54aa03987c4958ac83 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 16 Sep 2021 11:03:04 +0200 Subject: speedup toUpperCase when called in parallel by removing locking from CharClass, which means we need to make it an immutable class Since SharedStringPool in sc/ stores a pointer to the CharClass in use, we have to tweak SvtSysLocale so that the object does not change location. Change-Id: I2c62d354fa542ebc04e755ce5b9b9e2ddff76a64 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122185 Tested-by: Jenkins Reviewed-by: Noel Grandin --- unotools/source/i18n/charclass.cxx | 133 +++++++------------------------------ unotools/source/misc/syslocale.cxx | 12 ++-- 2 files changed, 31 insertions(+), 114 deletions(-) (limited to 'unotools') diff --git a/unotools/source/i18n/charclass.cxx b/unotools/source/i18n/charclass.cxx index c326e4315681..dee05388e150 100644 --- a/unotools/source/i18n/charclass.cxx +++ b/unotools/source/i18n/charclass.cxx @@ -33,16 +33,13 @@ CharClass::CharClass( const Reference< uno::XComponentContext > & rxContext, const LanguageTag& rLanguageTag ) - : - maLanguageTag( rLanguageTag) + : maLanguageTag( rLanguageTag) { xCC = CharacterClassification::create( rxContext ); } -CharClass::CharClass( - const LanguageTag& rLanguageTag ) - : - maLanguageTag( rLanguageTag) +CharClass::CharClass( const LanguageTag& rLanguageTag ) + : maLanguageTag( rLanguageTag) { xCC = CharacterClassification::create( comphelper::getProcessComponentContext() ); } @@ -51,21 +48,13 @@ CharClass::~CharClass() { } -void CharClass::setLanguageTag( const LanguageTag& rLanguageTag ) -{ - std::scoped_lock aGuard( aMutex ); - maLanguageTag = rLanguageTag; -} - const LanguageTag& CharClass::getLanguageTag() const { - std::scoped_lock aGuard( aMutex ); return maLanguageTag; } const css::lang::Locale& CharClass::getMyLocale() const { - // Mutex locked by callers. return maLanguageTag.getLocale(); } @@ -113,12 +102,8 @@ bool CharClass::isAlpha( const OUString& rStr, sal_Int32 nPos ) const try { - if ( xCC.is() ) - { - std::scoped_lock aGuard( aMutex ); - return (xCC->getCharacterType( rStr, nPos, getMyLocale() ) & - nCharClassAlphaType) != 0; - } + return (xCC->getCharacterType( rStr, nPos, getMyLocale() ) & + nCharClassAlphaType) != 0; } catch ( const Exception& ) { @@ -135,12 +120,8 @@ bool CharClass::isLetter( const OUString& rStr, sal_Int32 nPos ) const try { - if ( xCC.is() ) - { - std::scoped_lock aGuard( aMutex ); - return (xCC->getCharacterType( rStr, nPos, getMyLocale() ) & - nCharClassLetterType) != 0; - } + return (xCC->getCharacterType( rStr, nPos, getMyLocale() ) & + nCharClassLetterType) != 0; } catch ( const Exception& ) { @@ -153,11 +134,7 @@ bool CharClass::isLetter( const OUString& rStr ) const { try { - if ( xCC.is() ) - { - std::scoped_lock aGuard( aMutex ); - return isLetterType( xCC->getStringType( rStr, 0, rStr.getLength(), getMyLocale() ) ); - } + return isLetterType( xCC->getStringType( rStr, 0, rStr.getLength(), getMyLocale() ) ); } catch ( const Exception& ) { @@ -174,12 +151,8 @@ bool CharClass::isDigit( const OUString& rStr, sal_Int32 nPos ) const try { - if ( xCC.is() ) - { - std::scoped_lock aGuard( aMutex ); - return (xCC->getCharacterType( rStr, nPos, getMyLocale() ) & - KCharacterType::DIGIT) != 0; - } + return (xCC->getCharacterType( rStr, nPos, getMyLocale() ) & + KCharacterType::DIGIT) != 0; } catch ( const Exception& ) { @@ -192,11 +165,7 @@ bool CharClass::isNumeric( const OUString& rStr ) const { try { - if ( xCC.is() ) - { - std::scoped_lock aGuard( aMutex ); - return isNumericType( xCC->getStringType( rStr, 0, rStr.getLength(), getMyLocale() ) ); - } + return isNumericType( xCC->getStringType( rStr, 0, rStr.getLength(), getMyLocale() ) ); } catch ( const Exception& ) { @@ -213,12 +182,8 @@ bool CharClass::isAlphaNumeric( const OUString& rStr, sal_Int32 nPos ) const try { - if ( xCC.is() ) - { - std::scoped_lock aGuard( aMutex ); - return (xCC->getCharacterType( rStr, nPos, getMyLocale() ) & + return (xCC->getCharacterType( rStr, nPos, getMyLocale() ) & (nCharClassAlphaType | KCharacterType::DIGIT)) != 0; - } } catch ( const Exception& ) { @@ -235,12 +200,8 @@ bool CharClass::isLetterNumeric( const OUString& rStr, sal_Int32 nPos ) const try { - if ( xCC.is() ) - { - std::scoped_lock aGuard( aMutex ); - return (xCC->getCharacterType( rStr, nPos, getMyLocale() ) & - (nCharClassLetterType | KCharacterType::DIGIT)) != 0; - } + return (xCC->getCharacterType( rStr, nPos, getMyLocale() ) & + (nCharClassLetterType | KCharacterType::DIGIT)) != 0; } catch ( const Exception& ) { @@ -253,11 +214,7 @@ bool CharClass::isLetterNumeric( const OUString& rStr ) const { try { - if ( xCC.is() ) - { - std::scoped_lock aGuard( aMutex ); - return isLetterNumericType( xCC->getStringType( rStr, 0, rStr.getLength(), getMyLocale() ) ); - } + return isLetterNumericType( xCC->getStringType( rStr, 0, rStr.getLength(), getMyLocale() ) ); } catch ( const Exception& ) { @@ -270,11 +227,7 @@ OUString CharClass::titlecase(const OUString& rStr, sal_Int32 nPos, sal_Int32 nC { try { - if ( xCC.is() ) - { - std::scoped_lock aGuard( aMutex ); - return xCC->toTitle( rStr, nPos, nCount, getMyLocale() ); - } + return xCC->toTitle( rStr, nPos, nCount, getMyLocale() ); } catch ( const Exception& ) { @@ -287,11 +240,7 @@ OUString CharClass::uppercase( const OUString& rStr, sal_Int32 nPos, sal_Int32 n { try { - if ( xCC.is() ) - { - std::scoped_lock aGuard( aMutex ); - return xCC->toUpper( rStr, nPos, nCount, getMyLocale() ); - } + return xCC->toUpper( rStr, nPos, nCount, getMyLocale() ); } catch ( const Exception& ) { @@ -304,11 +253,7 @@ OUString CharClass::lowercase( const OUString& rStr, sal_Int32 nPos, sal_Int32 n { try { - if ( xCC.is() ) - { - std::scoped_lock aGuard( aMutex ); - return xCC->toLower( rStr, nPos, nCount, getMyLocale() ); - } + return xCC->toLower( rStr, nPos, nCount, getMyLocale() ); } catch ( const Exception& ) { @@ -321,11 +266,7 @@ sal_Int16 CharClass::getType( const OUString& rStr, sal_Int32 nPos ) const { try { - if ( xCC.is() ) - { - std::scoped_lock aGuard( aMutex ); - return xCC->getType( rStr, nPos ); - } + return xCC->getType( rStr, nPos ); } catch ( const Exception& ) { @@ -338,11 +279,7 @@ css::i18n::DirectionProperty CharClass::getCharacterDirection( const OUString& r { try { - if ( xCC.is() ) - { - std::scoped_lock aGuard( aMutex ); - return static_cast(xCC->getCharacterDirection( rStr, nPos )); - } + return static_cast(xCC->getCharacterDirection( rStr, nPos )); } catch ( const Exception& ) { @@ -355,11 +292,7 @@ css::i18n::UnicodeScript CharClass::getScript( const OUString& rStr, sal_Int32 n { try { - if ( xCC.is() ) - { - std::scoped_lock aGuard( aMutex ); - return static_cast(xCC->getScript( rStr, nPos )); - } + return static_cast(xCC->getScript( rStr, nPos )); } catch ( const Exception& ) { @@ -372,11 +305,7 @@ sal_Int32 CharClass::getCharacterType( const OUString& rStr, sal_Int32 nPos ) co { try { - if ( xCC.is() ) - { - std::scoped_lock aGuard( aMutex ); - return xCC->getCharacterType( rStr, nPos, getMyLocale() ); - } + return xCC->getCharacterType( rStr, nPos, getMyLocale() ); } catch ( const Exception& ) { @@ -389,11 +318,7 @@ sal_Int32 CharClass::getStringType( const OUString& rStr, sal_Int32 nPos, sal_In { try { - if ( xCC.is() ) - { - std::scoped_lock aGuard( aMutex ); - return xCC->getStringType( rStr, nPos, nCount, getMyLocale() ); - } + return xCC->getStringType( rStr, nPos, nCount, getMyLocale() ); } catch ( const Exception& ) { @@ -412,13 +337,9 @@ css::i18n::ParseResult CharClass::parseAnyToken( { try { - if ( xCC.is() ) - { - std::scoped_lock aGuard( aMutex ); - return xCC->parseAnyToken( rStr, nPos, getMyLocale(), + return xCC->parseAnyToken( rStr, nPos, getMyLocale(), nStartCharFlags, userDefinedCharactersStart, nContCharFlags, userDefinedCharactersCont ); - } } catch ( const Exception& ) { @@ -438,13 +359,9 @@ css::i18n::ParseResult CharClass::parsePredefinedToken( { try { - if ( xCC.is() ) - { - std::scoped_lock aGuard( aMutex ); - return xCC->parsePredefinedToken( nTokenType, rStr, nPos, getMyLocale(), + return xCC->parsePredefinedToken( nTokenType, rStr, nPos, getMyLocale(), nStartCharFlags, userDefinedCharactersStart, nContCharFlags, userDefinedCharactersCont ); - } } catch ( const Exception& ) { diff --git a/unotools/source/misc/syslocale.cxx b/unotools/source/misc/syslocale.cxx index 2882eb7fc436..b55e1316cabe 100644 --- a/unotools/source/misc/syslocale.cxx +++ b/unotools/source/misc/syslocale.cxx @@ -47,8 +47,8 @@ class SvtSysLocale_Impl : public utl::ConfigurationListener { public: SvtSysLocaleOptions aSysLocaleOptions; - std::unique_ptr pLocaleData; - std::unique_ptr pCharClass; + std::unique_ptr pLocaleData; + std::optional moCharClass; SvtSysLocale_Impl(); virtual ~SvtSysLocale_Impl() override; @@ -77,9 +77,9 @@ SvtSysLocale_Impl::~SvtSysLocale_Impl() CharClass& SvtSysLocale_Impl::GetCharClass() { - if ( !pCharClass ) - pCharClass.reset(new CharClass( aSysLocaleOptions.GetRealLanguageTag() )); - return *pCharClass; + if ( !moCharClass ) + moCharClass.emplace( aSysLocaleOptions.GetRealLanguageTag() ); + return *moCharClass; } void SvtSysLocale_Impl::ConfigurationChanged( utl::ConfigurationBroadcaster*, ConfigurationHints nHint ) @@ -93,7 +93,7 @@ void SvtSysLocale_Impl::ConfigurationChanged( utl::ConfigurationBroadcaster*, Co const LanguageTag& rLanguageTag = aSysLocaleOptions.GetRealLanguageTag(); if ( nHint & ConfigurationHints::Locale ) { - GetCharClass().setLanguageTag( rLanguageTag ); + moCharClass.emplace( rLanguageTag ); } pLocaleData.reset(new LocaleDataWrapper(rLanguageTag, getDateAcceptancePatternsConfig())); } -- cgit