From 3b53aa7cb6284182c58056b376c1b57dd1414062 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 14 Jun 2023 13:03:58 +0200 Subject: speed up startup time by avoid conversion of static locale data from sal_Unicode to OUString data - we can declare the data as OUStringConstExpr arrays and then no conversion is necessary. Change-Id: I95214d09938036935a45e8b8e9752596246dd2e1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153058 Tested-by: Jenkins Reviewed-by: Noel Grandin --- i18npool/source/localedata/LocaleNode.cxx | 38 ++++++++++++++++--------------- i18npool/source/localedata/localedata.cxx | 32 +++++++++++--------------- 2 files changed, 33 insertions(+), 37 deletions(-) (limited to 'i18npool') diff --git a/i18npool/source/localedata/LocaleNode.cxx b/i18npool/source/localedata/LocaleNode.cxx index e0cac2020d4c..b70cae2c713f 100644 --- a/i18npool/source/localedata/LocaleNode.cxx +++ b/i18npool/source/localedata/LocaleNode.cxx @@ -1316,8 +1316,8 @@ void LCCollationNode::generateCode (const OFileWriter &of) const OUString useLocale = getAttr().getValueByName("ref"); if (!useLocale.isEmpty()) { useLocale = useLocale.replace( '-', '_'); - of.writeRefFunction("getCollatorImplementation_", useLocale); - of.writeRefFunction("getCollationOptions_", useLocale); + of.writeOUStringRefFunction("getCollatorImplementation_", useLocale); + of.writeOUStringRefFunction("getCollationOptions_", useLocale); return; } sal_Int16 nbOfCollations = 0; @@ -1329,11 +1329,11 @@ void LCCollationNode::generateCode (const OFileWriter &of) const { OUString str; str = currNode->getAttr().getValueByName("unoid"); - of.writeParameter("CollatorID", str, j); + of.writeOUStringLiteralParameter("CollatorID", str, j); str = currNode->getValue(); - of.writeParameter("CollatorRule", str, j); + of.writeOUStringLiteralParameter("CollatorRule", str, j); str = currNode -> getAttr().getValueByName("default"); - of.writeDefaultParameter("Collator", str, j); + of.writeOUStringLiteralDefaultParameter("Collator", str, j); of.writeAsciiString("\n"); nbOfCollations++; @@ -1344,7 +1344,7 @@ void LCCollationNode::generateCode (const OFileWriter &of) const nbOfCollationOptions = sal::static_int_cast( pCollationOptions->getNumberOfChildren() ); for( sal_Int16 i=0; igetChildAt( i )->getValue(), i ); + of.writeOUStringLiteralParameter("collationOption", pCollationOptions->getChildAt( i )->getValue(), i ); } of.writeAsciiString("static const sal_Int16 nbOfCollationOptions = "); @@ -1356,7 +1356,7 @@ void LCCollationNode::generateCode (const OFileWriter &of) const of.writeInt(nbOfCollations); of.writeAsciiString(";\n\n"); - of.writeAsciiString("\nstatic const sal_Unicode* LCCollatorArray[] = {\n"); + of.writeAsciiString("\nstatic constexpr rtl::OUStringConstExpr LCCollatorArray[] = {\n"); for(sal_Int16 j = 0; j < nbOfCollations; j++) { of.writeAsciiString("\tCollatorID"); of.writeInt(j); @@ -1372,16 +1372,17 @@ void LCCollationNode::generateCode (const OFileWriter &of) const } of.writeAsciiString("};\n\n"); - of.writeAsciiString("static const sal_Unicode* collationOptions[] = {"); + of.writeAsciiString("static constexpr rtl::OUStringConstExpr collationOptions[] = {"); for( sal_Int16 j=0; jgetNumberOfChildren(); for( i=0; igetChildAt( i )->getValue(), sal::static_int_cast(i) ); + of.writeOUStringLiteralParameter("searchOption", pSearchOptions->getChildAt( i )->getValue(), sal::static_int_cast(i) ); } of.writeAsciiString("static const sal_Int16 nbOfSearchOptions = "); of.writeInt( sal::static_int_cast( nSearchOptions ) ); of.writeAsciiString(";\n\n"); - of.writeAsciiString("static const sal_Unicode* searchOptions[] = {"); + of.writeAsciiString("static constexpr rtl::OUStringConstExpr searchOptions[] = {"); for( i=0; i(i) ); - of.writeAsciiString( ", " ); } - of.writeAsciiString("NULL };\n"); - of.writeFunction("getSearchOptions_", "nbOfSearchOptions", "searchOptions"); + of.writeAsciiString(" };\n"); + of.writeOUStringFunction("getSearchOptions_", "nbOfSearchOptions", "searchOptions"); } void LCIndexNode::generateCode (const OFileWriter &of) const diff --git a/i18npool/source/localedata/localedata.cxx b/i18npool/source/localedata/localedata.cxx index 12149ca14ff7..3f45df6cdd1a 100644 --- a/i18npool/source/localedata/localedata.cxx +++ b/i18npool/source/localedata/localedata.cxx @@ -904,13 +904,13 @@ LocaleDataImpl::getDateAcceptancePatterns( const Locale& rLocale ) OUString LocaleDataImpl::getCollatorRuleByAlgorithm( const Locale& rLocale, std::u16string_view algorithm ) { - MyFunc_Type func = reinterpret_cast(getFunctionSymbol( rLocale, "getCollatorImplementation" )); + MyFuncOUString_Type func = reinterpret_cast(getFunctionSymbol( rLocale, "getCollatorImplementation" )); if ( func ) { sal_Int16 collatorCount = 0; - sal_Unicode **collatorArray = func(collatorCount); + OUString const *collatorArray = func(collatorCount); for(sal_Int16 i = 0; i < collatorCount; i++) if (algorithm == collatorArray[i * COLLATOR_ELEMENTS + COLLATOR_OFFSET_ALGO]) - return OUString(collatorArray[i * COLLATOR_ELEMENTS + COLLATOR_OFFSET_RULE]); + return collatorArray[i * COLLATOR_ELEMENTS + COLLATOR_OFFSET_RULE]; } return OUString(); } @@ -919,18 +919,17 @@ LocaleDataImpl::getCollatorRuleByAlgorithm( const Locale& rLocale, std::u16strin Sequence< Implementation > SAL_CALL LocaleDataImpl::getCollatorImplementations( const Locale& rLocale ) { - MyFunc_Type func = reinterpret_cast(getFunctionSymbol( rLocale, "getCollatorImplementation" )); + MyFuncOUString_Type func = reinterpret_cast(getFunctionSymbol( rLocale, "getCollatorImplementation" )); if ( func ) { sal_Int16 collatorCount = 0; - sal_Unicode **collatorArray = func(collatorCount); + OUString const *collatorArray = func(collatorCount); Sequence< Implementation > seq(collatorCount); auto seqRange = asNonConstRange(seq); for(sal_Int16 i = 0; i < collatorCount; i++) { - Implementation impl( - OUString(collatorArray[i * COLLATOR_ELEMENTS + COLLATOR_OFFSET_ALGO]), + seqRange[i] = Implementation( + collatorArray[i * COLLATOR_ELEMENTS + COLLATOR_OFFSET_ALGO], collatorArray[i * COLLATOR_ELEMENTS + COLLATOR_OFFSET_DEFAULT][0] != 0); - seqRange[i] = impl; } return seq; } @@ -942,15 +941,15 @@ LocaleDataImpl::getCollatorImplementations( const Locale& rLocale ) Sequence< OUString > SAL_CALL LocaleDataImpl::getCollationOptions( const Locale& rLocale ) { - MyFunc_Type func = reinterpret_cast(getFunctionSymbol( rLocale, "getCollationOptions" )); + MyFuncOUString_Type func = reinterpret_cast(getFunctionSymbol( rLocale, "getCollationOptions" )); if ( func ) { sal_Int16 optionsCount = 0; - sal_Unicode **optionsArray = func(optionsCount); + OUString const *optionsArray = func(optionsCount); Sequence< OUString > seq(optionsCount); auto seqRange = asNonConstRange(seq); for(sal_Int16 i = 0; i < optionsCount; i++) { - seqRange[i] = OUString( optionsArray[i] ); + seqRange[i] = optionsArray[i]; } return seq; } @@ -962,17 +961,12 @@ LocaleDataImpl::getCollationOptions( const Locale& rLocale ) Sequence< OUString > SAL_CALL LocaleDataImpl::getSearchOptions( const Locale& rLocale ) { - MyFunc_Type func = reinterpret_cast(getFunctionSymbol( rLocale, "getSearchOptions" )); + MyFuncOUString_Type func = reinterpret_cast(getFunctionSymbol( rLocale, "getSearchOptions" )); if ( func ) { sal_Int16 optionsCount = 0; - sal_Unicode **optionsArray = func(optionsCount); - Sequence< OUString > seq(optionsCount); - auto seqRange = asNonConstRange(seq); - for(sal_Int16 i = 0; i < optionsCount; i++) { - seqRange[i] = OUString( optionsArray[i] ); - } - return seq; + OUString const *optionsArray = func(optionsCount); + return Sequence< OUString >(optionsArray, optionsCount); } else { return {}; -- cgit