diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-06-13 21:39:31 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-06-14 08:47:00 +0200 |
commit | ee76ed70e97448082f4c00c5c4207a44e1a91617 (patch) | |
tree | daeeaa234ef92bc004141c069c87a88db2743f43 /i18npool | |
parent | 3af9bd139458b534ae72e3e010c8725b826fd12c (diff) |
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: Iecc822169a2fcd2f4678e4d6c303083c54a54456
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153005
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'i18npool')
-rw-r--r-- | i18npool/inc/localedata.hxx | 2 | ||||
-rw-r--r-- | i18npool/source/localedata/LocaleNode.cxx | 109 | ||||
-rw-r--r-- | i18npool/source/localedata/LocaleNode.hxx | 4 | ||||
-rw-r--r-- | i18npool/source/localedata/filewriter.cxx | 26 | ||||
-rw-r--r-- | i18npool/source/localedata/localedata.cxx | 21 |
5 files changed, 94 insertions, 68 deletions
diff --git a/i18npool/inc/localedata.hxx b/i18npool/inc/localedata.hxx index f86954791f99..063637ca67f9 100644 --- a/i18npool/inc/localedata.hxx +++ b/i18npool/inc/localedata.hxx @@ -162,7 +162,7 @@ private: /// /// @throws css::uno::RuntimeException css::uno::Sequence< css::i18n::CalendarItem2 > getCalendarItems( - sal_Unicode const * const * const allCalendars, + OUString const * allCalendars, sal_Int16 & rnOffset, const sal_Int16 nWhichItem, const sal_Int16 nCalendar, diff --git a/i18npool/source/localedata/LocaleNode.cxx b/i18npool/source/localedata/LocaleNode.cxx index 0d24bc22e89a..08bf772321ad 100644 --- a/i18npool/source/localedata/LocaleNode.cxx +++ b/i18npool/source/localedata/LocaleNode.cxx @@ -1485,9 +1485,9 @@ static void lcl_writeAbbrFullNarrNames( const OFileWriter & of, const LocaleNode sal_uInt32 nChar = aFullName.iterateCodePoints( &o3tl::temporary(sal_Int32(0))); aNarrName = OUString( &nChar, 1); } - of.writeParameter( elementTag, "DefaultAbbrvName", aAbbrName, i, j); - of.writeParameter( elementTag, "DefaultFullName", aFullName, i, j); - of.writeParameter( elementTag, "DefaultNarrowName", aNarrName, i, j); + of.writeOUStringLiteralParameter( elementTag, "DefaultAbbrvName", aAbbrName, i, j); + of.writeOUStringLiteralParameter( elementTag, "DefaultFullName", aFullName, i, j); + of.writeOUStringLiteralParameter( elementTag, "DefaultNarrowName", aNarrName, i, j); } static void lcl_writeTabTagString( const OFileWriter & of, const char* pTag, const char* pStr ) @@ -1550,7 +1550,7 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const OUString useLocale = getAttr().getValueByName("ref"); if (!useLocale.isEmpty()) { useLocale = useLocale.replace( '-', '_'); - of.writeRefFunction("getAllCalendars_", useLocale); + of.writeOUStringRefFunction("getAllCalendars_", useLocale); return; } sal_Int16 nbOfCalendars = sal::static_int_cast<sal_Int16>( getNumberOfChildren() ); @@ -1585,7 +1585,7 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const for ( i = 0; i < nbOfCalendars; i++) { LocaleNode * calNode = getChildAt (i); OUString calendarID = calNode -> getAttr().getValueByName("unoid"); - of.writeParameter( "calendarID", calendarID, i); + of.writeOUStringLiteralParameter( "calendarID", calendarID, i); bool bGregorian = calendarID == "gregorian"; if (!bHasGregorian) bHasGregorian = bGregorian; @@ -1597,7 +1597,7 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const else calIt->second = true; str = calNode -> getAttr().getValueByName("default"); - of.writeDefaultParameter("Calendar", str, i); + of.writeOUStringLiteralDefaultParameter("Calendar", str, i); sal_Int16 nChild = 0; @@ -1614,8 +1614,8 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const } } if (!ref_name.isEmpty() && daysNode == nullptr) { - of.writeParameter("dayRef", u"ref", i); - of.writeParameter("dayRefName", ref_name, i); + of.writeOUStringLiteralParameter("dayRef", u"ref", i); + of.writeOUStringLiteralParameter("dayRefName", ref_name, i); nbOfDays[i] = 0; } else { if (daysNode == nullptr) @@ -1627,7 +1627,7 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const for (j = 0; j < nbOfDays[i]; j++) { LocaleNode *currNode = daysNode -> getChildAt(j); OUString dayID( currNode->getChildAt(0)->getValue()); - of.writeParameter("dayID", dayID, i, j); + of.writeOUStringLiteralParameter("dayID", dayID, i, j); if ( j == 0 && bGregorian && dayID != "sun" ) incError( "First day of a week of a Gregorian calendar must be <DayID>sun</DayID>"); lcl_writeAbbrFullNarrNames( of, currNode, elementTag, i, j); @@ -1647,8 +1647,8 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const } } if (!ref_name.isEmpty() && monthsNode == nullptr) { - of.writeParameter("monthRef", u"ref", i); - of.writeParameter("monthRefName", ref_name, i); + of.writeOUStringLiteralParameter("monthRef", u"ref", i); + of.writeOUStringLiteralParameter("monthRefName", ref_name, i); nbOfMonths[i] = 0; } else { if (monthsNode == nullptr) @@ -1660,7 +1660,7 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const for (j = 0; j < nbOfMonths[i]; j++) { LocaleNode *currNode = monthsNode -> getChildAt(j); OUString monthID( currNode->getChildAt(0)->getValue()); - of.writeParameter("monthID", monthID, i, j); + of.writeOUStringLiteralParameter("monthID", monthID, i, j); if ( j == 0 && bGregorian && monthID != "jan" ) incError( "First month of a year of a Gregorian calendar must be <MonthID>jan</MonthID>"); lcl_writeAbbrFullNarrNames( of, currNode, elementTag, i, j); @@ -1683,8 +1683,8 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const } } if (!ref_name.isEmpty() && genitiveMonthsNode == nullptr) { - of.writeParameter("genitiveMonthRef", u"ref", i); - of.writeParameter("genitiveMonthRefName", ref_name, i); + of.writeOUStringLiteralParameter("genitiveMonthRef", u"ref", i); + of.writeOUStringLiteralParameter("genitiveMonthRefName", ref_name, i); nbOfGenitiveMonths[i] = 0; } else { if (genitiveMonthsNode == nullptr) @@ -1696,7 +1696,7 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const for (j = 0; j < nbOfGenitiveMonths[i]; j++) { LocaleNode *currNode = genitiveMonthsNode -> getChildAt(j); OUString genitiveMonthID( currNode->getChildAt(0)->getValue()); - of.writeParameter("genitiveMonthID", genitiveMonthID, i, j); + of.writeOUStringLiteralParameter("genitiveMonthID", genitiveMonthID, i, j); if ( j == 0 && bGregorian && genitiveMonthID != "jan" ) incError( "First genitive month of a year of a Gregorian calendar must be <MonthID>jan</MonthID>"); lcl_writeAbbrFullNarrNames( of, currNode, elementTag, i, j); @@ -1720,8 +1720,8 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const } } if (!ref_name.isEmpty() && partitiveMonthsNode == nullptr) { - of.writeParameter("partitiveMonthRef", u"ref", i); - of.writeParameter("partitiveMonthRefName", ref_name, i); + of.writeOUStringLiteralParameter("partitiveMonthRef", u"ref", i); + of.writeOUStringLiteralParameter("partitiveMonthRefName", ref_name, i); nbOfPartitiveMonths[i] = 0; } else { if (partitiveMonthsNode == nullptr) @@ -1733,7 +1733,7 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const for (j = 0; j < nbOfPartitiveMonths[i]; j++) { LocaleNode *currNode = partitiveMonthsNode -> getChildAt(j); OUString partitiveMonthID( currNode->getChildAt(0)->getValue()); - of.writeParameter("partitiveMonthID", partitiveMonthID, i, j); + of.writeOUStringLiteralParameter("partitiveMonthID", partitiveMonthID, i, j); if ( j == 0 && bGregorian && partitiveMonthID != "jan" ) incError( "First partitive month of a year of a Gregorian calendar must be <MonthID>jan</MonthID>"); lcl_writeAbbrFullNarrNames( of, currNode, elementTag, i, j); @@ -1753,8 +1753,8 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const } } if (!ref_name.isEmpty() && erasNode == nullptr) { - of.writeParameter("eraRef", u"ref", i); - of.writeParameter("eraRefName", ref_name, i); + of.writeOUStringLiteralParameter("eraRef", u"ref", i); + of.writeOUStringLiteralParameter("eraRefName", ref_name, i); nbOfEras[i] = 0; } else { if (erasNode == nullptr) @@ -1776,14 +1776,14 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const continue; // for } OUString eraID( currNode->getChildAt(0)->getValue()); - of.writeParameter("eraID", eraID, i, j); + of.writeOUStringLiteralParameter("eraID", eraID, i, j); if ( j == 0 && bGregorian && eraID != "bc" ) incError( "First era of a Gregorian calendar must be <EraID>bc</EraID>"); if ( j == 1 && bGregorian && eraID != "ad" ) incError( "Second era of a Gregorian calendar must be <EraID>ad</EraID>"); of.writeAsciiString("\n"); - of.writeParameter(elementTag, "DefaultAbbrvName",currNode->getChildAt(1)->getValue() ,i, j); - of.writeParameter(elementTag, "DefaultFullName",currNode->getChildAt(2)->getValue() , i, j); + of.writeOUStringLiteralParameter(elementTag, "DefaultAbbrvName",currNode->getChildAt(1)->getValue() ,i, j); + of.writeOUStringLiteralParameter(elementTag, "DefaultFullName",currNode->getChildAt(2)->getValue() , i, j); } } } @@ -1804,7 +1804,7 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const if (j >= nbOfDays[i]) incErrorStr( "Error: <StartDayOfWeek> <DayID> must be one of the <DaysOfWeek>, but is: %s\n", str); } - of.writeParameter("startDayOfWeek", str, i); + of.writeOUStringLiteralParameter("startDayOfWeek", str, i); ++nChild; } @@ -1815,7 +1815,7 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const if (nDays < 1 || (0 < nbOfDays[i] && nbOfDays[i] < nDays)) incErrorInt( "Error: Bad value of MinimalDaysInFirstWeek: %d, must be 1 <= value <= days_in_week\n", nDays); - of.writeIntParameter("minimalDaysInFirstWeek", i, nDays); + of.writeOUStringLiteralIntParameter("minimalDaysInFirstWeek", i, nDays); } } if (!bHasGregorian) @@ -1825,48 +1825,43 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const of.writeInt(nbOfCalendars); of.writeAsciiString(";\n\n"); - of.writeAsciiString("static const sal_Unicode nbOfDays[] = {"); - for(i = 0; i < nbOfCalendars - 1; i++) { - of.writeInt(nbOfDays[i]); - of.writeAsciiString(", "); + of.writeAsciiString("static const OUStringLiteral nbOfDays = u\""); + for(i = 0; i < nbOfCalendars; i++) { + of.writeAsciiString("\\x"); + of.writeHexInt(nbOfDays[i]); } - of.writeInt(nbOfDays[i]); - of.writeAsciiString("};\n"); + of.writeAsciiString("\";\n"); - of.writeAsciiString("static const sal_Unicode nbOfMonths[] = {"); - for(i = 0; i < nbOfCalendars - 1; i++) { - of.writeInt(nbOfMonths[i]); - of.writeAsciiString(", "); + of.writeAsciiString("static const OUStringLiteral nbOfMonths = u\""); + for(i = 0; i < nbOfCalendars; i++) { + of.writeAsciiString("\\x"); + of.writeHexInt(nbOfMonths[i]); } - of.writeInt(nbOfMonths[i]); - of.writeAsciiString("};\n"); + of.writeAsciiString("\";\n"); - of.writeAsciiString("static const sal_Unicode nbOfGenitiveMonths[] = {"); - for(i = 0; i < nbOfCalendars - 1; i++) { - of.writeInt(nbOfGenitiveMonths[i]); - of.writeAsciiString(", "); + of.writeAsciiString("static const OUStringLiteral nbOfGenitiveMonths = u\""); + for(i = 0; i < nbOfCalendars; i++) { + of.writeAsciiString("\\x"); + of.writeHexInt(nbOfGenitiveMonths[i]); } - of.writeInt(nbOfGenitiveMonths[i]); - of.writeAsciiString("};\n"); + of.writeAsciiString("\";\n"); - of.writeAsciiString("static const sal_Unicode nbOfPartitiveMonths[] = {"); - for(i = 0; i < nbOfCalendars - 1; i++) { - of.writeInt(nbOfPartitiveMonths[i]); - of.writeAsciiString(", "); + of.writeAsciiString("static const OUStringLiteral nbOfPartitiveMonths = u\""); + for(i = 0; i < nbOfCalendars; i++) { + of.writeAsciiString("\\x"); + of.writeHexInt(nbOfPartitiveMonths[i]); } - of.writeInt(nbOfPartitiveMonths[i]); - of.writeAsciiString("};\n"); + of.writeAsciiString("\";\n"); - of.writeAsciiString("static const sal_Unicode nbOfEras[] = {"); - for(i = 0; i < nbOfCalendars - 1; i++) { - of.writeInt(nbOfEras[i]); - of.writeAsciiString(", "); + of.writeAsciiString("static const OUStringLiteral nbOfEras = u\""); + for(i = 0; i < nbOfCalendars; i++) { + of.writeAsciiString("\\x"); + of.writeHexInt(nbOfEras[i]); } - of.writeInt(nbOfEras[i]); - of.writeAsciiString("};\n"); + of.writeAsciiString("\";\n"); - of.writeAsciiString("static const sal_Unicode* calendars[] = {\n"); + of.writeAsciiString("static constexpr rtl::OUStringConstExpr calendars[] = {\n"); of.writeAsciiString("\tnbOfDays,\n"); of.writeAsciiString("\tnbOfMonths,\n"); of.writeAsciiString("\tnbOfGenitiveMonths,\n"); @@ -1889,7 +1884,7 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const } of.writeAsciiString("};\n\n"); - of.writeFunction("getAllCalendars_", "calendarsCount", "calendars"); + of.writeOUStringFunction("getAllCalendars_", "calendarsCount", "calendars"); } static bool isIso4217( const OUString& rStr ) diff --git a/i18npool/source/localedata/LocaleNode.hxx b/i18npool/source/localedata/LocaleNode.hxx index b7528407d41d..16765f6c42e7 100644 --- a/i18npool/source/localedata/LocaleNode.hxx +++ b/i18npool/source/localedata/LocaleNode.hxx @@ -40,9 +40,11 @@ public: void writeOUStringLiteralCharacters(std::u16string_view str) const; void writeAsciiString(const char *str)const ; void writeInt(sal_Int16 nb) const; + void writeHexInt(sal_Int16 nb) const; void writeOUStringRefFunction(const char *func, std::u16string_view useLocale) const; void writeOUStringRefFunction(const char *func, std::u16string_view useLocale, const char *to) const; void writeFunction(const char *func, const char *count, const char *array) const; + void writeOUStringFunction(const char *func, const char *count, const char *array) const; void writeRefFunction(const char *func, std::u16string_view useLocale) const; void writeFunction(const char *func, const char *count, const char *array, const char *from, const char *to) const; void writeOUStringFunction(const char *func, const char *count, const char *array, const char *from, const char *to) const; @@ -59,8 +61,10 @@ public: void writeParameter(const char* pAsciiStr, std::u16string_view aChars, sal_Int16 count) const; void writeOUStringLiteralParameter(const char* pAsciiStr, std::u16string_view aChars, sal_Int16 count) const; void writeParameter(const char* pAsciiStr, std::u16string_view aChars, sal_Int16 count0, sal_Int16 count1) const; + void writeOUStringLiteralParameter(const char* pAsciiStr, std::u16string_view aChars, sal_Int16 count0, sal_Int16 count1) const; void writeParameter(const char* pTagStr, const char* pAsciiStr, std::u16string_view aChars, const sal_Int16 count) const; void writeParameter(const char* pTagStr, const char* pAsciiStr, std::u16string_view aChars, sal_Int16 count0, sal_Int16 count1) const; + void writeOUStringLiteralParameter(const char* pTagStr, const char* pAsciiStr, std::u16string_view aChars, sal_Int16 count0, sal_Int16 count1) const; void closeOutput() const; /// Return the locale string, something like en_US or de_DE const char * getLocale() const { return theLocale.c_str(); } diff --git a/i18npool/source/localedata/filewriter.cxx b/i18npool/source/localedata/filewriter.cxx index 91768b2bd54e..de75307b3596 100644 --- a/i18npool/source/localedata/filewriter.cxx +++ b/i18npool/source/localedata/filewriter.cxx @@ -39,6 +39,11 @@ void OFileWriter::writeInt(sal_Int16 nb) const fprintf(m_f, "%d", nb); } +void OFileWriter::writeHexInt(sal_Int16 nb) const +{ + fprintf(m_f, "%x", nb); +} + void OFileWriter::writeAsciiString(const char* str) const { fprintf(m_f, "%s", str); @@ -83,6 +88,13 @@ void OFileWriter::writeFunction(const char *func, const char *count, const char fprintf(m_f, "\treturn (sal_Unicode**)%s;\n}\n", array); } +void OFileWriter::writeOUStringFunction(const char *func, const char *count, const char *array) const +{ + fprintf(m_f, "OUString const * SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale.c_str()); + fprintf(m_f, "\tcount = %s;\n", count); + fprintf(m_f, "\treturn (OUString const *)%s;\n}\n", array); +} + void OFileWriter::writeRefFunction(const char *func, std::u16string_view useLocale) const { OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) ); @@ -208,6 +220,13 @@ void OFileWriter::writeParameter(const char* pAsciiStr, std::u16string_view aCha fprintf(m_f, "0x0};\n"); } +void OFileWriter::writeOUStringLiteralParameter(const char* pAsciiStr, std::u16string_view aChars, sal_Int16 count0, sal_Int16 count1) const +{ + fprintf(m_f, "static constexpr OUStringLiteral %s%d%d = u\"", pAsciiStr, count0, count1); + writeOUStringLiteralCharacters(aChars); + fprintf(m_f, "\";\n"); +} + void OFileWriter::writeParameter(const char* pTagStr, const char* pAsciiStr, std::u16string_view aChars, const sal_Int16 count) const { fprintf(m_f, "static const sal_Unicode %s%s%d[] = {", pTagStr, pAsciiStr, count); @@ -222,6 +241,13 @@ void OFileWriter::writeParameter(const char* pTagStr, const char* pAsciiStr, std fprintf(m_f, "0x0};\n"); } +void OFileWriter::writeOUStringLiteralParameter(const char* pTagStr, const char* pAsciiStr, std::u16string_view aChars, sal_Int16 count0, sal_Int16 count1) const +{ + fprintf(m_f, "static constexpr OUStringLiteral %s%s%d%d = u\"", pTagStr, pAsciiStr, count0, count1); + writeOUStringLiteralCharacters(aChars); + fprintf(m_f, "\";\n"); +} + void OFileWriter::closeOutput() const { if(m_f) diff --git a/i18npool/source/localedata/localedata.cxx b/i18npool/source/localedata/localedata.cxx index 975a7ce47a14..0494357b10a3 100644 --- a/i18npool/source/localedata/localedata.cxx +++ b/i18npool/source/localedata/localedata.cxx @@ -43,6 +43,7 @@ using namespace com::sun::star::lang; using namespace com::sun::star; typedef sal_Unicode** (* MyFunc_Type)( sal_Int16&); +typedef OUString const * (* MyFuncOUString_Type)( sal_Int16&); typedef sal_Unicode const *** (* MyFunc_Type2)( sal_Int16&, sal_Int16& ); typedef sal_Unicode const **** (* MyFunc_Type3)( sal_Int16&, sal_Int16&, sal_Int16& ); typedef OUString const * (* MyFunc_FormatCode)( sal_Int16&, sal_Unicode const *&, sal_Unicode const *& ); @@ -679,14 +680,14 @@ Sequence< CalendarItem2 > &LocaleDataImpl::getCalendarItemByName(const OUString& } Sequence< CalendarItem2 > LocaleDataImpl::getCalendarItems( - sal_Unicode const * const * const allCalendars, sal_Int16 & rnOffset, + OUString const * allCalendars, sal_Int16 & rnOffset, const sal_Int16 nWhichItem, const sal_Int16 nCalendar, const Locale & rLocale, const Sequence< Calendar2 > & calendarsSeq ) { Sequence< CalendarItem2 > aItems; if ( allCalendars[rnOffset] == std::u16string_view(u"ref") ) { - aItems = getCalendarItemByName( OUString( allCalendars[rnOffset+1]), rLocale, calendarsSeq, nWhichItem); + aItems = getCalendarItemByName( allCalendars[rnOffset+1], rLocale, calendarsSeq, nWhichItem); rnOffset += 2; } else @@ -701,9 +702,9 @@ Sequence< CalendarItem2 > LocaleDataImpl::getCalendarItems( case REF_PMONTHS: for (CalendarItem2& rItem : asNonConstRange(aItems)) { - rItem = CalendarItem2{ OUString(allCalendars[rnOffset]), - OUString(allCalendars[rnOffset+1]), - OUString(allCalendars[rnOffset+2]), OUString(allCalendars[rnOffset+3])}; + rItem = CalendarItem2{ allCalendars[rnOffset], + allCalendars[rnOffset+1], + allCalendars[rnOffset+2], allCalendars[rnOffset+3]}; rnOffset += 4; } break; @@ -711,9 +712,9 @@ Sequence< CalendarItem2 > LocaleDataImpl::getCalendarItems( // Absent narrow name. for (CalendarItem2& rItem : asNonConstRange(aItems)) { - rItem = CalendarItem2{ OUString(allCalendars[rnOffset]), - OUString(allCalendars[rnOffset+1]), - OUString(allCalendars[rnOffset+2]), OUString()}; + rItem = CalendarItem2{ allCalendars[rnOffset], + allCalendars[rnOffset+1], + allCalendars[rnOffset+2], OUString()}; rnOffset += 3; } break; @@ -728,9 +729,9 @@ Sequence< Calendar2 > SAL_CALL LocaleDataImpl::getAllCalendars2( const Locale& rLocale ) { - sal_Unicode const * const * allCalendars = nullptr; + OUString const * allCalendars = nullptr; - MyFunc_Type func = reinterpret_cast<MyFunc_Type>(getFunctionSymbol( rLocale, "getAllCalendars" )); + MyFuncOUString_Type func = reinterpret_cast<MyFuncOUString_Type>(getFunctionSymbol( rLocale, "getAllCalendars" )); if ( func ) { sal_Int16 calendarsCount = 0; |