unotools/source/config/docinfohelper.cxx |  118 ++++++++++++++++---------------
 1 file changed, 61 insertions(+), 57 deletions(-)

New commits:
commit c5340bdf444ae74f3778a2cf9f90d5db6c9ef153
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Sun May 15 13:02:18 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sun May 15 21:40:17 2022 +0200

    cache string in DocInfoHelper::GetGeneratorString
    
    since it doesn't change
    
    Change-Id: I8a9eee18b6de5f375ee2d4d67cdf48700590d007
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134347
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/unotools/source/config/docinfohelper.cxx 
b/unotools/source/config/docinfohelper.cxx
index 735f0ac2d56e..6b36fb21b7e3 100644
--- a/unotools/source/config/docinfohelper.cxx
+++ b/unotools/source/config/docinfohelper.cxx
@@ -31,74 +31,78 @@ namespace utl
 
 OUString DocInfoHelper::GetGeneratorString()
 {
-    OUString aResultOverride = 
officecfg::Office::Common::Save::Document::GeneratorOverride::get();
-    if( !aResultOverride.isEmpty())
-        return aResultOverride;
-
-    OUStringBuffer aResult(128);
-
-    // First product: branded name + version
-    // version is <product_versions>_<product_extension>$<platform>
+    static const OUString sGenerator = []()
+            {
+            OUString aResultOverride = 
officecfg::Office::Common::Save::Document::GeneratorOverride::get();
+            if( !aResultOverride.isEmpty())
+                return aResultOverride;
 
-    // plain product name
-    OUString aValue( utl::ConfigManager::getProductName() );
-    if ( !aValue.isEmpty() )
-    {
-        aResult.append( aValue.replace( ' ', '_' ) );
-        aResult.append( '/' );
+            OUStringBuffer aResult(128);
 
-        aValue = utl::ConfigManager::getProductVersion();
-        if ( !aValue.isEmpty() )
-        {
-            aResult.append( aValue.replace( ' ', '_' ) );
+            // First product: branded name + version
+            // version is <product_versions>_<product_extension>$<platform>
 
-            aValue = utl::ConfigManager::getProductExtension();
+            // plain product name
+            OUString aValue( utl::ConfigManager::getProductName() );
             if ( !aValue.isEmpty() )
             {
                 aResult.append( aValue.replace( ' ', '_' ) );
-            }
-        }
+                aResult.append( '/' );
 
-        OUString os( "$_OS" );
-        OUString arch( "$_ARCH" );
-        ::rtl::Bootstrap::expandMacros(os);
-        ::rtl::Bootstrap::expandMacros(arch);
-        aResult.append( '$' );
-        aResult.append( os );
-        aResult.append( '_' );
-        aResult.append( arch );
-        aResult.append( ' ' );
-    }
+                aValue = utl::ConfigManager::getProductVersion();
+                if ( !aValue.isEmpty() )
+                {
+                    aResult.append( aValue.replace( ' ', '_' ) );
 
-    // second product: LibreOffice_project/<build_information>
-    // build_information has '(' and '[' encoded as '$', ')' and ']' ignored
-    // and ':' replaced by '-'
-    {
-        aResult.append( "LibreOffice_project/" );
-        OUString aBuildId( Bootstrap::getBuildIdData( OUString() ) );
-        for( sal_Int32 i=0; i < aBuildId.getLength(); i++ )
-        {
-            sal_Unicode c = aBuildId[i];
-            switch( c )
-            {
-            case '(':
-            case '[':
+                    aValue = utl::ConfigManager::getProductExtension();
+                    if ( !aValue.isEmpty() )
+                    {
+                        aResult.append( aValue.replace( ' ', '_' ) );
+                    }
+                }
+
+                OUString os( "$_OS" );
+                OUString arch( "$_ARCH" );
+                ::rtl::Bootstrap::expandMacros(os);
+                ::rtl::Bootstrap::expandMacros(arch);
                 aResult.append( '$' );
-                break;
-            case ')':
-            case ']':
-                break;
-            case ':':
-                aResult.append( '-' );
-                break;
-            default:
-                aResult.append( c );
-                break;
+                aResult.append( os );
+                aResult.append( '_' );
+                aResult.append( arch );
+                aResult.append( ' ' );
+            }
+
+            // second product: LibreOffice_project/<build_information>
+            // build_information has '(' and '[' encoded as '$', ')' and ']' 
ignored
+            // and ':' replaced by '-'
+            {
+                aResult.append( "LibreOffice_project/" );
+                OUString aBuildId( Bootstrap::getBuildIdData( OUString() ) );
+                for( sal_Int32 i=0; i < aBuildId.getLength(); i++ )
+                {
+                    sal_Unicode c = aBuildId[i];
+                    switch( c )
+                    {
+                    case '(':
+                    case '[':
+                        aResult.append( '$' );
+                        break;
+                    case ')':
+                    case ']':
+                        break;
+                    case ':':
+                        aResult.append( '-' );
+                        break;
+                    default:
+                        aResult.append( c );
+                        break;
+                    }
+                }
             }
-        }
-    }
 
-    return aResult.makeStringAndClear();
+            return aResult.makeStringAndClear();
+    }();
+    return sGenerator;
 }
 
 } // end of namespace utl

Reply via email to