sc/source/filter/excel/xeescher.cxx |   22 +++++++++++-----------
 sc/source/filter/inc/xeescher.hxx   |    8 +++++---
 2 files changed, 16 insertions(+), 14 deletions(-)

New commits:
commit 6754b647c145cded1f54b49d53d37ad35ace211c
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Mon Sep 19 18:51:23 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Sep 20 09:17:00 2022 +0200

    simplify usage of TempFile in sc
    
    TempFile already handles the stream. And not touching the URL
    means we stay on the fast path for temp files.
    
    Change-Id: I15f51b75d3bb8ed53d617fce373237f685d45e00
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140204
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/source/filter/excel/xeescher.cxx 
b/sc/source/filter/excel/xeescher.cxx
index 6f931acd75e3..241d448e2992 100644
--- a/sc/source/filter/excel/xeescher.cxx
+++ b/sc/source/filter/excel/xeescher.cxx
@@ -1934,14 +1934,14 @@ XclExpObjectManager::XclExpObjectManager( const 
XclExpRoot& rRoot ) :
     XclExpRoot( rRoot )
 {
     InitStream( true );
-    mxEscherEx = std::make_shared<XclEscherEx>( GetRoot(), *this, *mxDffStrm );
+    mxEscherEx = std::make_shared<XclEscherEx>( GetRoot(), *this, *mpDffStrm );
 }
 
 XclExpObjectManager::XclExpObjectManager( const XclExpObjectManager& rParent ) 
:
     XclExpRoot( rParent.GetRoot() )
 {
     InitStream( false );
-    mxEscherEx = std::make_shared<XclEscherEx>( GetRoot(), *this, *mxDffStrm, 
rParent.mxEscherEx.get() );
+    mxEscherEx = std::make_shared<XclEscherEx>( GetRoot(), *this, *mpDffStrm, 
rParent.mxEscherEx.get() );
 }
 
 XclExpObjectManager::~XclExpObjectManager()
@@ -2016,18 +2016,18 @@ void XclExpObjectManager::InitStream( bool bTempFile )
 {
     if( bTempFile )
     {
-        mxTempFile = std::make_shared<::utl::TempFile>();
-        if( mxTempFile->IsValid() )
-        {
-            mxTempFile->EnableKillingFile();
-            mxDffStrm = ::utl::UcbStreamHelper::CreateStream( 
mxTempFile->GetURL(), StreamMode::STD_READWRITE );
-        }
+        moTempFile.emplace();
+        moTempFile->EnableKillingFile();
+        mpDffStrm = moTempFile->GetStream( StreamMode::STD_READWRITE );
     }
 
-    if( !mxDffStrm )
-        mxDffStrm = std::make_unique<SvMemoryStream>();
+    if( !mpDffStrm )
+    {
+        mpBackupStrm = std::make_unique<SvMemoryStream>();
+        mpDffStrm = mpBackupStrm.get();
+    }
 
-    mxDffStrm->SetEndian( SvStreamEndian::LITTLE );
+    mpDffStrm->SetEndian( SvStreamEndian::LITTLE );
 }
 
 XclExpEmbeddedObjectManager::XclExpEmbeddedObjectManager(
diff --git a/sc/source/filter/inc/xeescher.hxx 
b/sc/source/filter/inc/xeescher.hxx
index c8b7ed8c5857..55e970ed4e86 100644
--- a/sc/source/filter/inc/xeescher.hxx
+++ b/sc/source/filter/inc/xeescher.hxx
@@ -26,11 +26,12 @@
 #include "xlformula.hxx"
 #include <svx/sdtaitm.hxx>
 #include <rtl/ustring.hxx>
+#include <unotools/tempfile.hxx>
 #include <memory>
+#include <optional>
 
 class ScPostIt;
 
-namespace utl { class TempFile; }
 namespace com::sun::star::chart { class XChartDocument; }
 namespace com::sun::star::script { struct ScriptEventDescriptor; }
 
@@ -437,8 +438,9 @@ private:
     void                InitStream( bool bTempFile );
 
 private:
-    std::shared_ptr< ::utl::TempFile > mxTempFile;
-    std::unique_ptr< SvStream >  mxDffStrm;
+    std::optional< ::utl::TempFile > moTempFile;
+    SvStream* mpDffStrm = nullptr;
+    std::unique_ptr<SvMemoryStream> mpBackupStrm;
     std::shared_ptr< XclEscherEx > mxEscherEx;
     rtl::Reference< XclExpObjList > mxObjList;
 };

Reply via email to