i18npool/inc/localedata.hxx               |    4 +-
 i18npool/source/localedata/LocaleNode.cxx |   59 +++++++++++++++++-------------
 i18npool/source/localedata/localedata.cxx |   41 +++++++++-----------
 3 files changed, 55 insertions(+), 49 deletions(-)

New commits:
commit 88304309b57abe1e50395c5f71862fabcd1c752e
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Jun 14 13:22:24 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Jun 15 13:05:29 2023 +0200

    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: Iae879408d6761098d0e73526a65863d8f3cdb9ed
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153059
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/i18npool/inc/localedata.hxx b/i18npool/inc/localedata.hxx
index 063637ca67f9..f4cd15a30254 100644
--- a/i18npool/inc/localedata.hxx
+++ b/i18npool/inc/localedata.hxx
@@ -149,8 +149,8 @@ private:
 
     /// @throws css::uno::RuntimeException
     oslGenericFunction getFunctionSymbol( const css::lang::Locale& rLocale, 
const char* pFunction );
-    sal_Unicode ** getIndexArray(const css::lang::Locale& rLocale, sal_Int16& 
indexCount);
-    sal_Unicode ** getIndexArrayForAlgorithm(const css::lang::Locale& rLocale, 
std::u16string_view rAlgorithm);
+    OUString const * getIndexArray(const css::lang::Locale& rLocale, 
sal_Int16& indexCount);
+    OUString const * getIndexArrayForAlgorithm(const css::lang::Locale& 
rLocale, std::u16string_view rAlgorithm);
     /// @throws css::uno::RuntimeException
     css::uno::Sequence< css::i18n::CalendarItem2 > &
         getCalendarItemByName(const OUString& name,
diff --git a/i18npool/source/localedata/LocaleNode.cxx 
b/i18npool/source/localedata/LocaleNode.cxx
index b70cae2c713f..49024a6bc97f 100644
--- a/i18npool/source/localedata/LocaleNode.cxx
+++ b/i18npool/source/localedata/LocaleNode.cxx
@@ -1430,9 +1430,9 @@ void LCIndexNode::generateCode (const OFileWriter &of) 
const
     OUString useLocale =   getAttr().getValueByName("ref");
     if (!useLocale.isEmpty()) {
         useLocale = useLocale.replace( '-', '_');
-        of.writeRefFunction("getIndexAlgorithm_", useLocale);
-        of.writeRefFunction("getUnicodeScripts_", useLocale);
-        of.writeRefFunction("getFollowPageWords_", useLocale);
+        of.writeOUStringRefFunction("getIndexAlgorithm_", useLocale);
+        of.writeOUStringRefFunction("getUnicodeScripts_", useLocale);
+        of.writeOUStringRefFunction("getFollowPageWords_", useLocale);
         return;
     }
     sal_Int16 nbOfIndexs = 0;
@@ -1444,28 +1444,28 @@ void LCIndexNode::generateCode (const OFileWriter &of) 
const
         {
             OUString str;
             str = currNode->getAttr().getValueByName("unoid");
-            of.writeParameter("IndexID", str, nbOfIndexs);
+            of.writeOUStringLiteralParameter("IndexID", str, nbOfIndexs);
             str = currNode->getAttr().getValueByName("module");
-            of.writeParameter("IndexModule", str, nbOfIndexs);
+            of.writeOUStringLiteralParameter("IndexModule", str, nbOfIndexs);
             str = currNode->getValue();
-            of.writeParameter("IndexKey", str, nbOfIndexs);
+            of.writeOUStringLiteralParameter("IndexKey", str, nbOfIndexs);
             str = currNode -> getAttr().getValueByName("default");
-            of.writeDefaultParameter("Index", str, nbOfIndexs);
+            of.writeOUStringLiteralDefaultParameter("Index", str, nbOfIndexs);
             str = currNode -> getAttr().getValueByName("phonetic");
-            of.writeDefaultParameter("Phonetic", str, nbOfIndexs);
+            of.writeOUStringLiteralDefaultParameter("Phonetic", str, 
nbOfIndexs);
             of.writeAsciiString("\n");
 
             nbOfIndexs++;
         }
         if( currNode->getName() == "UnicodeScript" )
         {
-            of.writeParameter("unicodeScript", currNode->getValue(), 
nbOfUnicodeScripts );
+            of.writeOUStringLiteralParameter("unicodeScript", 
currNode->getValue(), nbOfUnicodeScripts );
             nbOfUnicodeScripts++;
 
         }
         if( currNode->getName() == "FollowPageWord" )
         {
-            of.writeParameter("followPageWord", currNode->getValue(), 
nbOfPageWords);
+            of.writeOUStringLiteralParameter("followPageWord", 
currNode->getValue(), nbOfPageWords);
             nbOfPageWords++;
         }
     }
@@ -1473,7 +1473,7 @@ void LCIndexNode::generateCode (const OFileWriter &of) 
const
     of.writeInt(nbOfIndexs);
     of.writeAsciiString(";\n\n");
 
-    of.writeAsciiString("\nstatic const sal_Unicode* IndexArray[] = {\n");
+    of.writeAsciiString("\nstatic constexpr rtl::OUStringConstExpr 
IndexArray[] = {\n");
     for(sal_Int16 i = 0; i < nbOfIndexs; i++) {
         of.writeAsciiString("\tIndexID");
         of.writeInt(i);
@@ -1501,30 +1501,41 @@ void LCIndexNode::generateCode (const OFileWriter &of) 
const
     of.writeInt( nbOfUnicodeScripts );
     of.writeAsciiString(";\n\n");
 
-    of.writeAsciiString("static const sal_Unicode* UnicodeScriptArray[] = {");
+    of.writeAsciiString("static constexpr rtl::OUStringConstExpr 
UnicodeScriptArray[] = {");
     for( sal_Int16 i=0; i<nbOfUnicodeScripts; i++ )
     {
+        if (i)
+            of.writeAsciiString( ", " );
         of.writeAsciiString( "unicodeScript" );
         of.writeInt( i );
-        of.writeAsciiString( ", " );
     }
-    of.writeAsciiString("NULL };\n\n");
+    of.writeAsciiString(" };\n\n");
 
     of.writeAsciiString("static const sal_Int16 nbOfPageWords = ");
     of.writeInt(nbOfPageWords);
     of.writeAsciiString(";\n\n");
 
-    of.writeAsciiString("static const sal_Unicode* FollowPageWordArray[] = 
{\n");
-    for(sal_Int16 i = 0; i < nbOfPageWords; i++) {
-        of.writeAsciiString("\tfollowPageWord");
-        of.writeInt(i);
-        of.writeAsciiString(",\n");
+    // MSVC doesnt like zero sized arrays
+    if (nbOfPageWords == 0)
+    {
+        // generate dummy array, reuse unicodeScript0 for dummy entry
+        of.writeAsciiString("//dummy array, we have zero entries\n");
+        of.writeAsciiString("static constexpr rtl::OUStringConstExpr 
FollowPageWordArray[] = { unicodeScript0 };\n\n");
     }
-    of.writeAsciiString("\tNULL\n};\n\n");
-
-    of.writeFunction("getIndexAlgorithm_", "nbOfIndexs", "IndexArray");
-    of.writeFunction("getUnicodeScripts_", "nbOfUnicodeScripts", 
"UnicodeScriptArray");
-    of.writeFunction("getFollowPageWords_", "nbOfPageWords", 
"FollowPageWordArray");
+    else
+    {
+        of.writeAsciiString("static constexpr rtl::OUStringConstExpr 
FollowPageWordArray[] = {\n");
+        for(sal_Int16 i = 0; i < nbOfPageWords; i++) {
+            if (i)
+                of.writeAsciiString(",\n");
+            of.writeAsciiString("\tfollowPageWord");
+            of.writeInt(i);
+        }
+        of.writeAsciiString("\t\n};\n\n");
+    }
+    of.writeOUStringFunction("getIndexAlgorithm_", "nbOfIndexs", "IndexArray");
+    of.writeOUStringFunction("getUnicodeScripts_", "nbOfUnicodeScripts", 
"UnicodeScriptArray");
+    of.writeOUStringFunction("getFollowPageWords_", "nbOfPageWords", 
"FollowPageWordArray");
 }
 
 
diff --git a/i18npool/source/localedata/localedata.cxx 
b/i18npool/source/localedata/localedata.cxx
index 3f45df6cdd1a..5b6c0c214bbb 100644
--- a/i18npool/source/localedata/localedata.cxx
+++ b/i18npool/source/localedata/localedata.cxx
@@ -973,10 +973,10 @@ LocaleDataImpl::getSearchOptions( const Locale& rLocale )
     }
 }
 
-sal_Unicode **
+OUString const *
 LocaleDataImpl::getIndexArray(const Locale& rLocale, sal_Int16& indexCount)
 {
-    MyFunc_Type func = reinterpret_cast<MyFunc_Type>(getFunctionSymbol( 
rLocale, "getIndexAlgorithm" ));
+    MyFuncOUString_Type func = 
reinterpret_cast<MyFuncOUString_Type>(getFunctionSymbol( rLocale, 
"getIndexAlgorithm" ));
 
     if (func)
         return func(indexCount);
@@ -987,7 +987,7 @@ Sequence< OUString >
 LocaleDataImpl::getIndexAlgorithm( const Locale& rLocale )
 {
     sal_Int16 indexCount = 0;
-    sal_Unicode **indexArray = getIndexArray(rLocale, indexCount);
+    OUString const *indexArray = getIndexArray(rLocale, indexCount);
 
     if ( indexArray ) {
         Sequence< OUString > seq(indexCount);
@@ -1006,12 +1006,12 @@ OUString
 LocaleDataImpl::getDefaultIndexAlgorithm( const Locale& rLocale )
 {
     sal_Int16 indexCount = 0;
-    sal_Unicode **indexArray = getIndexArray(rLocale, indexCount);
+    OUString const *indexArray = getIndexArray(rLocale, indexCount);
 
     if ( indexArray ) {
         for(sal_Int16 i = 0; i < indexCount; i++) {
             if (indexArray[i*5 + 3][0])
-                return OUString(indexArray[i*5]);
+                return indexArray[i*5];
         }
     }
     return OUString();
@@ -1021,7 +1021,7 @@ bool
 LocaleDataImpl::hasPhonetic( const Locale& rLocale )
 {
     sal_Int16 indexCount = 0;
-    sal_Unicode **indexArray = getIndexArray(rLocale, indexCount);
+    OUString const *indexArray = getIndexArray(rLocale, indexCount);
 
     if ( indexArray ) {
         for(sal_Int16 i = 0; i < indexCount; i++) {
@@ -1032,11 +1032,11 @@ LocaleDataImpl::hasPhonetic( const Locale& rLocale )
     return false;
 }
 
-sal_Unicode **
+OUString const *
 LocaleDataImpl::getIndexArrayForAlgorithm(const Locale& rLocale, 
std::u16string_view algorithm)
 {
     sal_Int16 indexCount = 0;
-    sal_Unicode **indexArray = getIndexArray(rLocale, indexCount);
+    OUString const *indexArray = getIndexArray(rLocale, indexCount);
     if ( indexArray ) {
         for(sal_Int16 i = 0; i < indexCount; i++) {
             if (algorithm == indexArray[i*5])
@@ -1049,36 +1049,36 @@ LocaleDataImpl::getIndexArrayForAlgorithm(const Locale& 
rLocale, std::u16string_
 bool
 LocaleDataImpl::isPhonetic( const Locale& rLocale, std::u16string_view 
algorithm )
 {
-    sal_Unicode **indexArray = getIndexArrayForAlgorithm(rLocale, algorithm);
+    OUString const *indexArray = getIndexArrayForAlgorithm(rLocale, algorithm);
     return indexArray && indexArray[4][0];
 }
 
 OUString
 LocaleDataImpl::getIndexKeysByAlgorithm( const Locale& rLocale, 
std::u16string_view algorithm )
 {
-    sal_Unicode **indexArray = getIndexArrayForAlgorithm(rLocale, algorithm);
+    OUString const *indexArray = getIndexArrayForAlgorithm(rLocale, algorithm);
     return indexArray ? (OUString::Concat(u"0-9") + indexArray[2]) : 
OUString();
 }
 
 OUString
 LocaleDataImpl::getIndexModuleByAlgorithm( const Locale& rLocale, 
std::u16string_view algorithm )
 {
-    sal_Unicode **indexArray = getIndexArrayForAlgorithm(rLocale, algorithm);
-    return indexArray ? OUString(indexArray[1]) : OUString();
+    OUString const *indexArray = getIndexArrayForAlgorithm(rLocale, algorithm);
+    return indexArray ? indexArray[1] : OUString();
 }
 
 Sequence< UnicodeScript >
 LocaleDataImpl::getUnicodeScripts( const Locale& rLocale )
 {
-    MyFunc_Type func = reinterpret_cast<MyFunc_Type>(getFunctionSymbol( 
rLocale, "getUnicodeScripts" ));
+    MyFuncOUString_Type func = 
reinterpret_cast<MyFuncOUString_Type>(getFunctionSymbol( rLocale, 
"getUnicodeScripts" ));
 
     if ( func ) {
         sal_Int16 scriptCount = 0;
-        sal_Unicode **scriptArray = func(scriptCount);
+        OUString const *scriptArray = func(scriptCount);
         Sequence< UnicodeScript > seq(scriptCount);
         auto seqRange = asNonConstRange(seq);
         for(sal_Int16 i = 0; i < scriptCount; i++) {
-            seqRange[i] = UnicodeScript( 
o3tl::toInt32(std::u16string_view(scriptArray[i], 1)) );
+            seqRange[i] = UnicodeScript( 
o3tl::toInt32(scriptArray[i].subView(0, 1)) );
         }
         return seq;
     }
@@ -1090,17 +1090,12 @@ LocaleDataImpl::getUnicodeScripts( const Locale& 
rLocale )
 Sequence< OUString >
 LocaleDataImpl::getFollowPageWords( const Locale& rLocale )
 {
-    MyFunc_Type func = reinterpret_cast<MyFunc_Type>(getFunctionSymbol( 
rLocale, "getFollowPageWords" ));
+    MyFuncOUString_Type func = 
reinterpret_cast<MyFuncOUString_Type>(getFunctionSymbol( rLocale, 
"getFollowPageWords" ));
 
     if ( func ) {
         sal_Int16 wordCount = 0;
-        sal_Unicode **wordArray = func(wordCount);
-        Sequence< OUString > seq(wordCount);
-        auto seqRange = asNonConstRange(seq);
-        for(sal_Int16 i = 0; i < wordCount; i++) {
-            seqRange[i] = OUString(wordArray[i]);
-        }
-        return seq;
+        OUString const *wordArray = func(wordCount);
+        return Sequence< OUString >(wordArray, wordCount);
     }
     else {
         return {};

Reply via email to