diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-06-13 21:10:01 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-06-14 08:46:51 +0200 |
commit | 3af9bd139458b534ae72e3e010c8725b826fd12c (patch) | |
tree | 8e853b038edb6d954963dee9877ca31cf351788f /i18npool | |
parent | 4e06ba6e57d8f1166b6e54924a7228b5c85962ba (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: I405806aef050e374b18a57cbf47e13a295821ccf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153004
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'i18npool')
-rw-r--r-- | i18npool/source/localedata/LocaleNode.cxx | 24 | ||||
-rw-r--r-- | i18npool/source/localedata/LocaleNode.hxx | 7 | ||||
-rw-r--r-- | i18npool/source/localedata/filewriter.cxx | 54 | ||||
-rw-r--r-- | i18npool/source/localedata/localedata.cxx | 19 | ||||
-rw-r--r-- | i18npool/source/localedata/saxparser.cxx | 1 |
5 files changed, 83 insertions, 22 deletions
diff --git a/i18npool/source/localedata/LocaleNode.cxx b/i18npool/source/localedata/LocaleNode.cxx index 14232338b9f1..0d24bc22e89a 100644 --- a/i18npool/source/localedata/LocaleNode.cxx +++ b/i18npool/source/localedata/LocaleNode.cxx @@ -562,11 +562,11 @@ void LCFormatNode::generateCode (const OFileWriter &of) const switch (mnSection) { case 0: - of.writeRefFunction("getAllFormats0_", useLocale, "replaceTo0"); + of.writeOUStringRefFunction("getAllFormats0_", useLocale, "replaceTo0"); of.writeRefFunction("getDateAcceptancePatterns_", useLocale); break; case 1: - of.writeRefFunction("getAllFormats1_", useLocale, "replaceTo1"); + of.writeOUStringRefFunction("getAllFormats1_", useLocale, "replaceTo1"); break; } ++mnSection; @@ -610,17 +610,17 @@ void LCFormatNode::generateCode (const OFileWriter &of) const str = currNodeAttr.getValueByName("msgid"); if (!aMsgIdSet.insert( str).second) incErrorStr( "Error: Duplicated msgid=\"%s\" in FormatElement.\n", str); - of.writeParameter("FormatKey", str, formatCount); + of.writeOUStringLiteralParameter("FormatKey", str, formatCount); str = currNodeAttr.getValueByName("default"); bool bDefault = str == "true"; - of.writeDefaultParameter("FormatElement", str, formatCount); + of.writeOUStringLiteralDefaultParameter("FormatElement", str, formatCount); aType = currNodeAttr.getValueByName("type"); - of.writeParameter("FormatType", aType, formatCount); + of.writeOUStringLiteralParameter("FormatType", aType, formatCount); aUsage = currNodeAttr.getValueByName("usage"); - of.writeParameter("FormatUsage", aUsage, formatCount); + of.writeOUStringLiteralParameter("FormatUsage", aUsage, formatCount); aFormatIndex = currNodeAttr.getValueByName("formatindex"); sal_Int16 formatindex = static_cast<sal_Int16>(aFormatIndex.toInt32()); @@ -636,7 +636,7 @@ void LCFormatNode::generateCode (const OFileWriter &of) const incErrorInt( "Error: Duplicated formatindex=\"%d\" in FormatElement.\n", formatindex); bShowNextFreeFormatIndex = true; } - of.writeIntParameter("Formatindex", formatCount, formatindex); + of.writeOUStringLiteralIntParameter("Formatindex", formatCount, formatindex); // Ensure only one default per usage and type. if (bDefault) @@ -652,7 +652,7 @@ void LCFormatNode::generateCode (const OFileWriter &of) const const LocaleNode * n = currNode -> findNode("FormatCode"); if (n) { - of.writeParameter("FormatCode", n->getValue(), formatCount); + of.writeOUStringLiteralParameter("FormatCode", n->getValue(), formatCount); // Check separator usage for some FormatCode elements. const LocaleNode* pCtype = nullptr; switch (formatindex) @@ -821,9 +821,9 @@ void LCFormatNode::generateCode (const OFileWriter &of) const incError( "No FormatCode in FormatElement."); n = currNode -> findNode("DefaultName"); if (n) - of.writeParameter("FormatDefaultName", n->getValue(), formatCount); + of.writeOUStringLiteralParameter("FormatDefaultName", n->getValue(), formatCount); else - of.writeParameter("FormatDefaultName", std::u16string_view(), formatCount); + of.writeOUStringLiteralParameter("FormatDefaultName", std::u16string_view(), formatCount); } @@ -918,7 +918,7 @@ void LCFormatNode::generateCode (const OFileWriter &of) const of.writeAsciiString(" = "); of.writeInt( formatCount - mnFormats); of.writeAsciiString(";\n"); - of.writeAsciiString("static const sal_Unicode* "); + of.writeAsciiString("static constexpr rtl::OUStringConstExpr "); of.writeAsciiString("FormatElementsArray"); of.writeInt(mnSection); of.writeAsciiString("[] = {\n"); @@ -964,7 +964,7 @@ void LCFormatNode::generateCode (const OFileWriter &of) const switch (mnSection) { case 0: - of.writeFunction("getAllFormats0_", "FormatElementsCount0", "FormatElementsArray0", "replaceFrom0", "replaceTo0"); + of.writeOUStringFunction("getAllFormats0_", "FormatElementsCount0", "FormatElementsArray0", "replaceFrom0", "replaceTo0"); break; case 1: of.writeFunction("getAllFormats1_", "FormatElementsCount1", "FormatElementsArray1", "replaceFrom1", "replaceTo1"); diff --git a/i18npool/source/localedata/LocaleNode.hxx b/i18npool/source/localedata/LocaleNode.hxx index e8c163c7e988..b7528407d41d 100644 --- a/i18npool/source/localedata/LocaleNode.hxx +++ b/i18npool/source/localedata/LocaleNode.hxx @@ -37,20 +37,27 @@ public: OFileWriter(const char *pcFile, const char *locale ); ~OFileWriter(); void writeStringCharacters(std::u16string_view str) const; + void writeOUStringLiteralCharacters(std::u16string_view str) const; void writeAsciiString(const char *str)const ; void writeInt(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 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; void writeRefFunction(const char *func, std::u16string_view useLocale, const char *to) const; void writeFunction2(const char *func, const char *style, const char* attr, const char *array) const; void writeRefFunction2(const char *func, std::u16string_view useLocale) const; void writeFunction3(const char *func, const char *style, const char* levels, const char* attr, const char *array) const; void writeRefFunction3(const char *func, std::u16string_view useLocale) const; void writeIntParameter(const char* pAsciiStr, const sal_Int16 count, sal_Int16 val) const; + void writeOUStringLiteralIntParameter(const char* pAsciiStr, const sal_Int16 count, sal_Int16 val) const; bool writeDefaultParameter(const char* pAsciiStr, std::u16string_view str, sal_Int16 count) const; + bool writeOUStringLiteralDefaultParameter(const char* pAsciiStr, std::u16string_view str, sal_Int16 count) const; void writeParameter(const char* pAsciiStr, std::u16string_view aChars) const; 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 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; diff --git a/i18npool/source/localedata/filewriter.cxx b/i18npool/source/localedata/filewriter.cxx index ca656a05b49d..91768b2bd54e 100644 --- a/i18npool/source/localedata/filewriter.cxx +++ b/i18npool/source/localedata/filewriter.cxx @@ -50,6 +50,32 @@ void OFileWriter::writeStringCharacters(std::u16string_view str) const fprintf(m_f, "0x%x, ", str[i]); } +void OFileWriter::writeOUStringLiteralCharacters(std::u16string_view str) const +{ + for(size_t i = 0; i < str.size(); i++) + fprintf(m_f, "\\x%x", str[i]); +} + +void OFileWriter::writeOUStringRefFunction(const char *func, std::u16string_view useLocale) const +{ + OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) ); + const char* locale = aRefLocale.getStr(); + fprintf(m_f, "extern const OUString * SAL_CALL %s%s(sal_Int16& count);\n", func, locale); + fprintf(m_f, "const OUString * SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale.c_str()); + fprintf(m_f, "\treturn %s%s(count);\n}\n", func, locale); +} + +void OFileWriter::writeOUStringRefFunction(const char *func, std::u16string_view useLocale, const char *to) const +{ + OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) ); + const char* locale = aRefLocale.getStr(); + fprintf(m_f, "extern OUString const * SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to);\n", func, locale); + fprintf(m_f, "OUString const * SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to)\n{\n", func, theLocale.c_str()); + fprintf(m_f, "\tto = %s;\n", to); + fprintf(m_f, "\tconst sal_Unicode* tmp;\n"); + fprintf(m_f, "\treturn %s%s(count, from, tmp);\n}\n", func, locale); +} + void OFileWriter::writeFunction(const char *func, const char *count, const char *array) const { fprintf(m_f, "sal_Unicode ** SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale.c_str()); @@ -75,6 +101,15 @@ 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 char *from, const char *to) const +{ + fprintf(m_f, "OUString const * SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to)\n{\n", func, theLocale.c_str()); + fprintf(m_f, "\tcount = %s;\n", count); + fprintf(m_f, "\tfrom = %s;\n", from); + fprintf(m_f, "\tto = %s;\n", to); + fprintf(m_f, "\treturn (const OUString *)%s;\n}\n", array); +} + void OFileWriter::writeRefFunction(const char *func, std::u16string_view useLocale, const char *to) const { OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) ); @@ -126,6 +161,11 @@ void OFileWriter::writeIntParameter(const char* pAsciiStr, const sal_Int16 count fprintf(m_f, "static const sal_Unicode %s%d[] = {%d};\n", pAsciiStr, count, val); } +void OFileWriter::writeOUStringLiteralIntParameter(const char* pAsciiStr, const sal_Int16 count, sal_Int16 val) const +{ + fprintf(m_f, "static constexpr OUStringLiteral %s%d = u\"\\x%x\";\n", pAsciiStr, count, val); +} + bool OFileWriter::writeDefaultParameter(const char* pAsciiStr, std::u16string_view str, sal_Int16 count) const { bool bBool = str == u"true"; @@ -133,6 +173,13 @@ bool OFileWriter::writeDefaultParameter(const char* pAsciiStr, std::u16string_vi return bBool; } +bool OFileWriter::writeOUStringLiteralDefaultParameter(const char* pAsciiStr, std::u16string_view str, sal_Int16 count) const +{ + bool bBool = str == u"true"; + fprintf(m_f,"static constexpr OUStringLiteral default%s%d = u\"\\x%x\";\n", pAsciiStr, count, bBool); + return bBool; +} + void OFileWriter::writeParameter(const char* pAsciiStr, std::u16string_view aChars) const { fprintf(m_f, "static const sal_Unicode %s[] = {", pAsciiStr); @@ -147,6 +194,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 count) const +{ + fprintf(m_f, "static constexpr OUStringLiteral %s%d = u\"", pAsciiStr, count); + writeOUStringLiteralCharacters(aChars); + fprintf(m_f, "\";\n"); +} + void OFileWriter::writeParameter(const char* pAsciiStr, std::u16string_view aChars, sal_Int16 count0, sal_Int16 count1) const { fprintf(m_f, "static const sal_Unicode %s%d%d[] = {", pAsciiStr, count0, count1); diff --git a/i18npool/source/localedata/localedata.cxx b/i18npool/source/localedata/localedata.cxx index 01f527a731d0..975a7ce47a14 100644 --- a/i18npool/source/localedata/localedata.cxx +++ b/i18npool/source/localedata/localedata.cxx @@ -45,7 +45,7 @@ using namespace com::sun::star; typedef sal_Unicode** (* MyFunc_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 sal_Unicode const * const * (* MyFunc_FormatCode)( sal_Int16&, sal_Unicode const *&, sal_Unicode const *& ); +typedef OUString const * (* MyFunc_FormatCode)( sal_Int16&, sal_Unicode const *&, sal_Unicode const *& ); #ifndef DISABLE_DYNLOADING @@ -830,7 +830,7 @@ LocaleDataImpl::getAllFormats( const Locale& rLocale ) MyFunc_FormatCode func; sal_Unicode const *from; sal_Unicode const *to; - sal_Unicode const *const *formatArray; + OUString const *formatArray; sal_Int16 formatCount; FormatSection() : func(nullptr), from(nullptr), to(nullptr), formatArray(nullptr), formatCount(0) {} @@ -852,20 +852,19 @@ LocaleDataImpl::getAllFormats( const Locale& rLocale ) sal_Int32 f = 0; for (const FormatSection & s : section) { - sal_Unicode const * const * const formatArray = s.formatArray; + OUString const * const formatArray = s.formatArray; if ( formatArray ) { for (int i = 0, nOff = 0; i < s.formatCount; ++i, nOff += 7, ++f) { - FormatElement elem( - OUString(formatArray[nOff]).replaceAll(s.from, s.to), - OUString(formatArray[nOff + 1]), - OUString(formatArray[nOff + 2]), - OUString(formatArray[nOff + 3]), - OUString(formatArray[nOff + 4]), + seqRange[f] = FormatElement( + formatArray[nOff].replaceAll(s.from, s.to), + formatArray[nOff + 1], + formatArray[nOff + 2], + formatArray[nOff + 3], + formatArray[nOff + 4], formatArray[nOff + 5][0], formatArray[nOff + 6][0] != 0); - seqRange[f] = elem; } } } diff --git a/i18npool/source/localedata/saxparser.cxx b/i18npool/source/localedata/saxparser.cxx index 8cad894951a1..603d91450b06 100644 --- a/i18npool/source/localedata/saxparser.cxx +++ b/i18npool/source/localedata/saxparser.cxx @@ -189,6 +189,7 @@ public: // ExtendedDocumentHandler { printf( "parsing document %s started\n", theLocale.c_str()); of.writeAsciiString("#include <sal/types.h>\n\n\n"); + of.writeAsciiString("#include <rtl/ustring.hxx>\n\n\n"); of.writeAsciiString("#include <stdio.h>\n\n"); of.writeAsciiString("extern \"C\" {\n\n"); } |