[Libreoffice-commits] core.git: comphelper/source sw/inc sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sat Dec 22 07:21:32 UTC 2018


 comphelper/source/officeinstdir/officeinstallationdirectories.cxx |   35 ++++------
 comphelper/source/officeinstdir/officeinstallationdirectories.hxx |    5 -
 sw/inc/crsrsh.hxx                                                 |    2 
 sw/source/core/crsr/findattr.cxx                                  |    8 +-
 sw/source/core/crsr/findtxt.cxx                                   |   18 ++---
 sw/source/uibase/uiview/viewsrch.cxx                              |    9 +-
 6 files changed, 37 insertions(+), 40 deletions(-)

New commits:
commit 05044640531055c86b34f1c6ec8055c8a0ca3df8
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Fri Dec 21 14:58:14 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sat Dec 22 08:21:12 2018 +0100

    use boost::optional for OUString
    
    instead of storing on heap
    
    Change-Id: I4ca2bb58ec4f71b161c9e6081f5e456de54d8153
    Reviewed-on: https://gerrit.libreoffice.org/65537
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/comphelper/source/officeinstdir/officeinstallationdirectories.cxx b/comphelper/source/officeinstdir/officeinstallationdirectories.cxx
index c6f91ffa7c1b..fae3d7c4f059 100644
--- a/comphelper/source/officeinstdir/officeinstallationdirectories.cxx
+++ b/comphelper/source/officeinstdir/officeinstallationdirectories.cxx
@@ -99,7 +99,7 @@ OUString SAL_CALL
 OfficeInstallationDirectories::getOfficeInstallationDirectoryURL()
 {
     initDirs();
-    return *m_pOfficeBrandDir;
+    return *m_xOfficeBrandDir;
 }
 
 
@@ -108,7 +108,7 @@ OUString SAL_CALL
 OfficeInstallationDirectories::getOfficeUserDataDirectoryURL()
 {
     initDirs();
-    return *m_pUserDir;
+    return *m_xUserDir;
 }
 
 
@@ -124,22 +124,22 @@ OfficeInstallationDirectories::makeRelocatableURL( const OUString& URL )
         OUString aCanonicalURL( URL );
         makeCanonicalFileURL( aCanonicalURL );
 
-        sal_Int32 nIndex = aCanonicalURL.indexOf( *m_pOfficeBrandDir );
+        sal_Int32 nIndex = aCanonicalURL.indexOf( *m_xOfficeBrandDir );
         if ( nIndex  != -1 )
         {
             return
                 aCanonicalURL.replaceAt( nIndex,
-                                         m_pOfficeBrandDir->getLength(),
+                                         m_xOfficeBrandDir->getLength(),
                                          g_aOfficeBrandDirMacro );
         }
         else
         {
-            nIndex = aCanonicalURL.indexOf( *m_pUserDir );
+            nIndex = aCanonicalURL.indexOf( *m_xUserDir );
             if ( nIndex  != -1 )
             {
                 return
                     aCanonicalURL.replaceAt( nIndex,
-                                             m_pUserDir->getLength(),
+                                             m_xUserDir->getLength(),
                                              g_aUserDirMacro );
             }
         }
@@ -162,7 +162,7 @@ OfficeInstallationDirectories::makeAbsoluteURL( const OUString& URL )
             return
                 URL.replaceAt( nIndex,
                                g_aOfficeBrandDirMacro.getLength(),
-                               *m_pOfficeBrandDir );
+                               *m_xOfficeBrandDir );
         }
         else
         {
@@ -174,7 +174,7 @@ OfficeInstallationDirectories::makeAbsoluteURL( const OUString& URL )
                 return
                     URL.replaceAt( nIndex,
                                    g_aUserDirMacro.getLength(),
-                                   *m_pUserDir );
+                                   *m_xUserDir );
             }
         }
     }
@@ -208,31 +208,28 @@ OfficeInstallationDirectories::getSupportedServiceNames()
 
 void OfficeInstallationDirectories::initDirs()
 {
-    if ( m_pOfficeBrandDir == nullptr )
+    if ( !m_xOfficeBrandDir)
     {
         osl::MutexGuard aGuard( m_aMutex );
-        if ( m_pOfficeBrandDir == nullptr )
+        if ( !m_xOfficeBrandDir )
         {
-            m_pOfficeBrandDir.reset( new OUString );
-            m_pUserDir.reset( new OUString );
-
             uno::Reference< util::XMacroExpander > xExpander = util::theMacroExpander::get(m_xCtx);
 
-            *m_pOfficeBrandDir = xExpander->expandMacros( "$BRAND_BASE_DIR" );
+            m_xOfficeBrandDir = xExpander->expandMacros( "$BRAND_BASE_DIR" );
 
-            OSL_ENSURE( !m_pOfficeBrandDir->isEmpty(),
+            OSL_ENSURE( !m_xOfficeBrandDir->isEmpty(),
                         "Unable to obtain office brand installation directory!" );
 
-            makeCanonicalFileURL( *m_pOfficeBrandDir );
+            makeCanonicalFileURL( *m_xOfficeBrandDir );
 
-            *m_pUserDir =
+            m_xUserDir =
                 xExpander->expandMacros(
                     "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE( "bootstrap" ) ":UserInstallation}" );
 
-            OSL_ENSURE( !m_pUserDir->isEmpty(),
+            OSL_ENSURE( !m_xUserDir->isEmpty(),
                         "Unable to obtain office user data directory!" );
 
-            makeCanonicalFileURL( *m_pUserDir );
+            makeCanonicalFileURL( *m_xUserDir );
         }
     }
 }
diff --git a/comphelper/source/officeinstdir/officeinstallationdirectories.hxx b/comphelper/source/officeinstdir/officeinstallationdirectories.hxx
index bfcde8d72876..e4fb6dd6a0f9 100644
--- a/comphelper/source/officeinstdir/officeinstallationdirectories.hxx
+++ b/comphelper/source/officeinstdir/officeinstallationdirectories.hxx
@@ -27,6 +27,7 @@
 #include <com/sun/star/uno/XComponentContext.hpp>
 #include <com/sun/star/util/XOfficeInstallationDirectories.hpp>
 #include <memory>
+#include <boost/optional.hpp>
 
 namespace comphelper {
 
@@ -70,8 +71,8 @@ private:
     void initDirs();
 
     css::uno::Reference< css::uno::XComponentContext >    m_xCtx;
-    std::unique_ptr<OUString>                  m_pOfficeBrandDir;
-    std::unique_ptr<OUString>                  m_pUserDir;
+    boost::optional<OUString>                  m_xOfficeBrandDir;
+    boost::optional<OUString>                  m_xUserDir;
 };
 
 } // namespace comphelper
diff --git a/sw/inc/crsrsh.hxx b/sw/inc/crsrsh.hxx
index a5c8e1acc4d2..423ed92fb1b4 100644
--- a/sw/inc/crsrsh.hxx
+++ b/sw/inc/crsrsh.hxx
@@ -132,7 +132,7 @@ bool ReplaceImpl(SwPaM & rCursor, OUString const& rReplacement,
         bool const bRegExp, SwDoc & rDoc, SwRootFrame const*const pLayout);
 
 /// Helperfunction to resolve backward references in regular expressions
-OUString *ReplaceBackReferences(const i18nutil::SearchOptions2& rSearchOpt,
+boost::optional<OUString> ReplaceBackReferences(const i18nutil::SearchOptions2& rSearchOpt,
         SwPaM* pPam, SwRootFrame const* pLayout );
 
 bool GetRanges(std::vector<std::shared_ptr<SwUnoCursor>> & rRanges,
diff --git a/sw/source/core/crsr/findattr.cxx b/sw/source/core/crsr/findattr.cxx
index 2fa9c20cb01a..bb6b5d34fa38 100644
--- a/sw/source/core/crsr/findattr.cxx
+++ b/sw/source/core/crsr/findattr.cxx
@@ -1313,11 +1313,11 @@ int SwFindParaAttr::DoFind(SwPaM & rCursor, SwMoveFnCollection const & fnMove,
             const_cast<SwPaM &>(rRegion).GetRingContainer().merge( m_rCursor.GetRingContainer() );
         }
 
-        std::unique_ptr<OUString> pRepl(bRegExp
-                ? sw::ReplaceBackReferences(*pSearchOpt, &rCursor, m_pLayout)
-                : nullptr);
+        boost::optional<OUString> xRepl;
+        if (bRegExp)
+            xRepl = sw::ReplaceBackReferences(*pSearchOpt, &rCursor, m_pLayout);
         sw::ReplaceImpl(rCursor,
-                pRepl ? *pRepl : pSearchOpt->replaceString, bRegExp,
+                xRepl ? *xRepl : pSearchOpt->replaceString, bRegExp,
                 *m_rCursor.GetDoc(), m_pLayout);
 
         m_rCursor.SaveTableBoxContent( rCursor.GetPoint() );
diff --git a/sw/source/core/crsr/findtxt.cxx b/sw/source/core/crsr/findtxt.cxx
index 796eeeeb4454..eeba1415994c 100644
--- a/sw/source/core/crsr/findtxt.cxx
+++ b/sw/source/core/crsr/findtxt.cxx
@@ -941,11 +941,11 @@ int SwFindParaText::DoFind(SwPaM & rCursor, SwMoveFnCollection const & fnMove,
             const_cast<SwPaM&>(rRegion).GetRingContainer().merge( m_rCursor.GetRingContainer() );
         }
 
-        std::unique_ptr<OUString> pRepl( bRegExp
-                ? sw::ReplaceBackReferences(m_rSearchOpt, &rCursor, m_pLayout)
-                : nullptr );
+        boost::optional<OUString> xRepl;
+        if (bRegExp)
+            xRepl = sw::ReplaceBackReferences(m_rSearchOpt, &rCursor, m_pLayout);
         bool const bReplaced = sw::ReplaceImpl(rCursor,
-                pRepl ? *pRepl : m_rSearchOpt.replaceString,
+                xRepl ? *xRepl : m_rSearchOpt.replaceString,
                 bRegExp, *m_rCursor.GetDoc(), m_pLayout);
 
         m_rCursor.SaveTableBoxContent( rCursor.GetPoint() );
@@ -1084,17 +1084,17 @@ bool ReplaceImpl(
     return bReplaced;
 }
 
-OUString *ReplaceBackReferences(const i18nutil::SearchOptions2& rSearchOpt,
+boost::optional<OUString> ReplaceBackReferences(const i18nutil::SearchOptions2& rSearchOpt,
         SwPaM *const pPam, SwRootFrame const*const pLayout)
 {
-    OUString *pRet = nullptr;
+    boost::optional<OUString> xRet;
     if( pPam && pPam->HasMark() &&
         SearchAlgorithms2::REGEXP == rSearchOpt.AlgorithmType2 )
     {
         const SwContentNode* pTextNode = pPam->GetContentNode();
         if (!pTextNode || !pTextNode->IsTextNode())
         {
-            return pRet;
+            return xRet;
         }
         SwTextFrame const*const pFrame(pLayout
             ? static_cast<SwTextFrame const*>(pTextNode->getLayoutFrame(pLayout))
@@ -1135,11 +1135,11 @@ OUString *ReplaceBackReferences(const i18nutil::SearchOptions2& rSearchOpt,
                 }
                 OUString aReplaceStr( rSearchOpt.replaceString );
                 aSText.ReplaceBackReferences( aReplaceStr, rStr, aResult );
-                pRet = new OUString( aReplaceStr );
+                xRet = aReplaceStr;
             }
         }
     }
-    return pRet;
+    return xRet;
 }
 
 } // namespace sw
diff --git a/sw/source/uibase/uiview/viewsrch.cxx b/sw/source/uibase/uiview/viewsrch.cxx
index c4d6bf2fce8b..a127c1a12241 100644
--- a/sw/source/uibase/uiview/viewsrch.cxx
+++ b/sw/source/uibase/uiview/viewsrch.cxx
@@ -309,15 +309,14 @@ void SwView::ExecSearch(SfxRequest& rReq)
                             m_pWrtShell->Push();
                         OUString aReplace( m_pSrchItem->GetReplaceString() );
                         i18nutil::SearchOptions2 aTmp( m_pSrchItem->GetSearchOptions() );
-                        OUString *pBackRef = sw::ReplaceBackReferences(aTmp,
+                        boost::optional<OUString> xBackRef = sw::ReplaceBackReferences(aTmp,
                             m_pWrtShell->GetCursor(), m_pWrtShell->GetLayout());
-                        if( pBackRef )
-                            m_pSrchItem->SetReplaceString( *pBackRef );
+                        if( xBackRef )
+                            m_pSrchItem->SetReplaceString( *xBackRef );
                         Replace();
-                        if( pBackRef )
+                        if( xBackRef )
                         {
                             m_pSrchItem->SetReplaceString( aReplace );
-                            delete pBackRef;
                         }
                         if (bBack)
                         {


More information about the Libreoffice-commits mailing list