diff options
-rw-r--r-- | sc/source/core/tool/interpr1.cxx | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index 9adedd0729ea..d4bd096e7fe9 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -3388,29 +3388,27 @@ void ScInterpreter::ScChar() static OUString lcl_convertIntoHalfWidth( const OUString & rStr ) { - static bool bFirstASCCall = true; - static utl::TransliterationWrapper aTrans( ::comphelper::getProcessComponentContext(), TransliterationFlags::NONE ); - - if( bFirstASCCall ) - { - aTrans.loadModuleByImplName( "FULLWIDTH_HALFWIDTH_LIKE_ASC", LANGUAGE_SYSTEM ); - bFirstASCCall = false; - } - + // Make the initialization thread-safe. Since another function needs to be called, move it all to another + // function and thread-safely initialize a static reference in this function. + auto init = []() -> utl::TransliterationWrapper& + { + static utl::TransliterationWrapper trans( ::comphelper::getProcessComponentContext(), TransliterationFlags::NONE ); + trans.loadModuleByImplName( "FULLWIDTH_HALFWIDTH_LIKE_ASC", LANGUAGE_SYSTEM ); + return trans; + }; + static utl::TransliterationWrapper& aTrans( init()); return aTrans.transliterate( rStr, 0, sal_uInt16( rStr.getLength() ) ); } static OUString lcl_convertIntoFullWidth( const OUString & rStr ) { - static bool bFirstJISCall = true; - static utl::TransliterationWrapper aTrans( ::comphelper::getProcessComponentContext(), TransliterationFlags::NONE ); - - if( bFirstJISCall ) - { - aTrans.loadModuleByImplName( "HALFWIDTH_FULLWIDTH_LIKE_JIS", LANGUAGE_SYSTEM ); - bFirstJISCall = false; - } - + auto init = []() -> utl::TransliterationWrapper& + { + static utl::TransliterationWrapper trans( ::comphelper::getProcessComponentContext(), TransliterationFlags::NONE ); + trans.loadModuleByImplName( "HALFWIDTH_FULLWIDTH_LIKE_JIS", LANGUAGE_SYSTEM ); + return trans; + }; + static utl::TransliterationWrapper& aTrans( init()); return aTrans.transliterate( rStr, 0, sal_uInt16( rStr.getLength() ) ); } |