sfx2/source/appl/childwin.cxx     |    6 +++---
 sfx2/source/appl/macroloader.cxx  |    4 ++--
 sfx2/source/appl/xpackcreator.cxx |   22 +++++++---------------
 sfx2/source/config/evntconf.cxx   |    6 +++---
 sfx2/source/doc/docinsert.cxx     |    8 ++++----
 5 files changed, 19 insertions(+), 27 deletions(-)

New commits:
commit af44198d80edce92bdbb82dfd6f218eeb6163484
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue May 31 09:57:02 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue May 31 14:55:23 2022 +0200

    these can be stack allocated
    
    Change-Id: Idd2e5e49ba4fcef2e80fd9c569f374a6a69f380e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135175
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sfx2/source/appl/childwin.cxx b/sfx2/source/appl/childwin.cxx
index 8fb4fa8f6a01..75d72cae0e2b 100644
--- a/sfx2/source/appl/childwin.cxx
+++ b/sfx2/source/appl/childwin.cxx
@@ -355,14 +355,14 @@ void 
SfxChildWindow::InitializeChildWinFactory_Impl(sal_uInt16 nId, SfxChildWinI
 {
     // load configuration
 
-    std::unique_ptr<SvtViewOptions> xWinOpt;
+    std::optional<SvtViewOptions> xWinOpt;
     // first see if a module specific id exists
     if (rInfo.aModule.getLength())
-        xWinOpt.reset(new SvtViewOptions(EViewType::Window, rInfo.aModule + 
"/" + OUString::number(nId)));
+        xWinOpt.emplace(EViewType::Window, rInfo.aModule + "/" + 
OUString::number(nId));
 
     // if not then try the generic id
     if (!xWinOpt || !xWinOpt->Exists())
-        xWinOpt.reset(new SvtViewOptions(EViewType::Window, 
OUString::number(nId)));
+        xWinOpt.emplace(EViewType::Window, OUString::number(nId));
 
     if (xWinOpt->Exists() && xWinOpt->HasVisible() )
         rInfo.bVisible  = xWinOpt->IsVisible(); // set state from 
configuration. Can be overwritten by UserData, see below
diff --git a/sfx2/source/appl/macroloader.cxx b/sfx2/source/appl/macroloader.cxx
index 0892bb78e4d9..a6fe07000187 100644
--- a/sfx2/source/appl/macroloader.cxx
+++ b/sfx2/source/appl/macroloader.cxx
@@ -283,9 +283,9 @@ ErrCode SfxMacroLoader::loadMacro( const OUString& rURL, 
css::uno::Any& rRetval,
 
                 {
                     // attempt to protect the document against the script 
tampering with its Undo Context
-                    std::unique_ptr< ::framework::DocumentUndoGuard > 
pUndoGuard;
+                    std::optional< ::framework::DocumentUndoGuard > pUndoGuard;
                     if ( bIsDocBasic )
-                        pUndoGuard.reset( new ::framework::DocumentUndoGuard( 
pDoc->GetModel() ) );
+                        pUndoGuard.emplace( pDoc->GetModel() );
 
                     // execute the method
                     SbxVariableRef retValRef = new SbxVariable;
diff --git a/sfx2/source/appl/xpackcreator.cxx 
b/sfx2/source/appl/xpackcreator.cxx
index 825a334f30ee..b9aa2b53cdcf 100644
--- a/sfx2/source/appl/xpackcreator.cxx
+++ b/sfx2/source/appl/xpackcreator.cxx
@@ -65,8 +65,6 @@ void SAL_CALL OPackageStructureCreator::convertToPackage( 
const OUString& aFolde
     ::ucbhelper::Content aContent;
     if( ::ucbhelper::Content::create( aFolderUrl, xComEnv, 
comphelper::getProcessComponentContext(), aContent ) )
     {
-        std::unique_ptr<SvStream> pTempStream;
-
         OUString aTempURL = ::utl::TempFile().GetURL();
         try {
             if ( aContent.isFolder() )
@@ -80,18 +78,18 @@ void SAL_CALL OPackageStructureCreator::convertToPackage( 
const OUString& aFolde
 
                 if ( !aTempURL.isEmpty() )
                 {
-                    pTempStream.reset(new SvFileStream( aTempURL, 
StreamMode::STD_READWRITE ));
-                    tools::SvRef<SotStorage> aTargetStorage = new SotStorage( 
true, *pTempStream );
+                    SvFileStream aTempStream( aTempURL, 
StreamMode::STD_READWRITE );
+                    tools::SvRef<SotStorage> aTargetStorage = new SotStorage( 
true, aTempStream );
                     aStorage->CopyTo( aTargetStorage.get() );
                     aTargetStorage->Commit();
 
-                    if ( aStorage->GetError() || aTargetStorage->GetError() || 
pTempStream->GetError() )
+                    if ( aStorage->GetError() || aTargetStorage->GetError() || 
aTempStream.GetError() )
                         throw io::IOException();
 
                     aTargetStorage = nullptr;
                     aStorage = nullptr;
 
-                    pTempStream->Seek( 0 );
+                    aTempStream.Seek( 0 );
 
                     uno::Sequence< sal_Int8 > aSeq( 32000 );
                     sal_uInt32 nRead = 0;
@@ -99,13 +97,13 @@ void SAL_CALL OPackageStructureCreator::convertToPackage( 
const OUString& aFolde
                         if ( aSeq.getLength() < 32000 )
                             aSeq.realloc( 32000 );
 
-                        nRead = pTempStream->ReadBytes(aSeq.getArray(), 32000);
+                        nRead = aTempStream.ReadBytes(aSeq.getArray(), 32000);
                         if ( nRead < 32000 )
                             aSeq.realloc( nRead );
                         xTargetStream->writeBytes( aSeq );
-                    } while (pTempStream->good() && nRead);
+                    } while (aTempStream.good() && nRead);
 
-                    if ( pTempStream->GetError() )
+                    if ( aTempStream.GetError() )
                         throw io::IOException();
 
                     bSuccess = true;
@@ -114,8 +112,6 @@ void SAL_CALL OPackageStructureCreator::convertToPackage( 
const OUString& aFolde
         }
         catch (const uno::RuntimeException&)
         {
-            pTempStream.reset();
-
             if ( !aTempURL.isEmpty() )
                 ::utl::UCBContentHelper::Kill( aTempURL );
 
@@ -123,8 +119,6 @@ void SAL_CALL OPackageStructureCreator::convertToPackage( 
const OUString& aFolde
         }
         catch (const io::IOException&)
         {
-            pTempStream.reset();
-
             if ( !aTempURL.isEmpty() )
                 ::utl::UCBContentHelper::Kill( aTempURL );
 
@@ -134,8 +128,6 @@ void SAL_CALL OPackageStructureCreator::convertToPackage( 
const OUString& aFolde
         {
         }
 
-        pTempStream.reset();
-
         if ( !aTempURL.isEmpty() )
             ::utl::UCBContentHelper::Kill( aTempURL );
     }
diff --git a/sfx2/source/config/evntconf.cxx b/sfx2/source/config/evntconf.cxx
index 914c7515d970..a6d44640af14 100644
--- a/sfx2/source/config/evntconf.cxx
+++ b/sfx2/source/config/evntconf.cxx
@@ -205,10 +205,10 @@ static void PropagateEvent_Impl( SfxObjectShell const 
*pDoc, const OUString& aEv
 
 void SfxEventConfiguration::ConfigureEvent( const OUString& aName, const 
SvxMacro& rMacro, SfxObjectShell const *pDoc )
 {
-    std::unique_ptr<SvxMacro> pMacro;
+    std::optional<SvxMacro> pMacro;
     if ( rMacro.HasMacro() )
-        pMacro.reset( new SvxMacro( rMacro.GetMacName(), rMacro.GetLibName(), 
rMacro.GetScriptType() ) );
-    PropagateEvent_Impl( pDoc ? pDoc : nullptr, aName, pMacro.get() );
+        pMacro.emplace( rMacro.GetMacName(), rMacro.GetLibName(), 
rMacro.GetScriptType() );
+    PropagateEvent_Impl( pDoc ? pDoc : nullptr, aName, pMacro ? &*pMacro : 
nullptr );
 }
 
 
diff --git a/sfx2/source/doc/docinsert.cxx b/sfx2/source/doc/docinsert.cxx
index 18d51016d579..d8fe42621a2a 100644
--- a/sfx2/source/doc/docinsert.cxx
+++ b/sfx2/source/doc/docinsert.cxx
@@ -110,18 +110,18 @@ std::unique_ptr<SfxMedium> 
DocumentInserter::CreateMedium(char const*const pFall
                 m_pURLList[0], SFX_STREAM_READONLY,
                 SfxGetpApp()->GetFilterMatcher().GetFilter4FilterName( 
m_sFilter ), m_xItemSet ));
         pMedium->UseInteractionHandler( true );
-        std::unique_ptr<SfxFilterMatcher> pMatcher;
+        std::optional<SfxFilterMatcher> pMatcher;
         if ( !m_sDocFactory.isEmpty() )
-            pMatcher.reset(new SfxFilterMatcher(m_sDocFactory));
+            pMatcher.emplace(m_sDocFactory);
         else
-            pMatcher.reset(new SfxFilterMatcher());
+            pMatcher.emplace();
 
         std::shared_ptr<const SfxFilter> pFilter;
         ErrCode nError = pMatcher->DetectFilter( *pMedium, pFilter );
         // tdf#101813 hack: check again if it's a global document
         if (ERRCODE_NONE != nError && pFallbackHack)
         {
-            pMatcher.reset(new 
SfxFilterMatcher(OUString::createFromAscii(pFallbackHack)));
+            pMatcher.emplace(OUString::createFromAscii(pFallbackHack));
             nError = pMatcher->DetectFilter( *pMedium, pFilter );
         }
         if ( nError == ERRCODE_NONE && pFilter )

Reply via email to