include/tools/stream.hxx | 4 +++- tools/source/stream/strmunx.cxx | 5 ++++- tools/source/stream/strmwnt.cxx | 5 ++++- unotools/source/ucbhelper/tempfile.cxx | 3 +++ 4 files changed, 14 insertions(+), 3 deletions(-)
New commits: commit 3837434dfb3a673a05d91b063e7ac2025589f32f Author: Noel Grandin <n...@peralex.com> AuthorDate: Mon Jun 21 12:54:29 2021 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Fri Jun 25 12:18:16 2021 +0200 tdf#135316 add SvFileStream::SetDontFlushOnClose if we're going to be deleting a temporary file, there is no point flushing it on close, which has a measureable cost This takes my load time from 17s to 16s Change-Id: I2fce7eeaf0ce9fef826b4ce9a1a4d4c8114cac76 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117607 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> (cherry picked from commit 9815bf197c27afdfeccf967898c3a000bcf7b256) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117731 diff --git a/include/tools/stream.hxx b/include/tools/stream.hxx index b55a45ff3022..17f2fbd4476b 100644 --- a/include/tools/stream.hxx +++ b/include/tools/stream.hxx @@ -49,7 +49,7 @@ enum class StreamMode { NOCREATE = 0x0004, ///< 1 == Don't create file TRUNC = 0x0008, ///< Truncate _existing_ file to zero length COPY_ON_SYMLINK = 0x0010, ///< copy-on-write for symlinks (Unix) - TEMPORARY = 0x0020, ///< temporary file attribute (Windows) + TEMPORARY = 0x0020, ///< temporary file attribute (Windows-only) // sharing options SHARE_DENYNONE = 0x0100, SHARE_DENYREAD = 0x0200, // overrides denynone @@ -586,6 +586,7 @@ private: sal_uInt16 nLockCounter; #endif bool bIsOpen; + bool mbDontFlushOnClose; ///< used to avoid flushing when closing temporary files SvFileStream (const SvFileStream&) = delete; SvFileStream & operator= (const SvFileStream&) = delete; @@ -612,6 +613,7 @@ public: bool IsOpen() const { return bIsOpen; } const OUString& GetFileName() const { return aFilename; } + void SetDontFlushOnClose(bool b) { mbDontFlushOnClose = b; } }; // MemoryStream diff --git a/tools/source/stream/strmunx.cxx b/tools/source/stream/strmunx.cxx index 40cbe382213a..ca5edc308602 100644 --- a/tools/source/stream/strmunx.cxx +++ b/tools/source/stream/strmunx.cxx @@ -197,6 +197,7 @@ SvFileStream::SvFileStream( const OUString& rFileName, StreamMode nOpenMode ) { bIsOpen = false; m_isWritable = false; + mbDontFlushOnClose = false; pInstanceData.reset(new StreamData); SetBufferSize( 1024 ); @@ -214,6 +215,7 @@ SvFileStream::SvFileStream() { bIsOpen = false; m_isWritable = false; + mbDontFlushOnClose = false; pInstanceData.reset(new StreamData); SetBufferSize( 1024 ); } @@ -455,7 +457,8 @@ void SvFileStream::Close() if ( IsOpen() ) { SAL_INFO("tools", "Closing " << aFilename); - Flush(); + if ( !mbDontFlushOnClose ) + Flush(); osl_closeFile( pInstanceData->rHandle ); pInstanceData->rHandle = nullptr; } diff --git a/tools/source/stream/strmwnt.cxx b/tools/source/stream/strmwnt.cxx index d85ce3a0c372..c91628b55091 100644 --- a/tools/source/stream/strmwnt.cxx +++ b/tools/source/stream/strmwnt.cxx @@ -107,6 +107,7 @@ SvFileStream::SvFileStream( const OUString& rFileName, StreamMode nMode ) bIsOpen = false; nLockCounter = 0; m_isWritable = false; + mbDontFlushOnClose = false; pInstanceData.reset( new StreamData ); SetBufferSize( 8192 ); @@ -123,6 +124,7 @@ SvFileStream::SvFileStream() bIsOpen = false; nLockCounter = 0; m_isWritable = false; + mbDontFlushOnClose = false; pInstanceData.reset( new StreamData ); SetBufferSize( 8192 ); @@ -377,7 +379,8 @@ void SvFileStream::Close() nLockCounter = 1; UnlockFile(); } - Flush(); + if ( !mbDontFlushOnClose ) + Flush(); CloseHandle( pInstanceData->hFile ); } bIsOpen = false; diff --git a/unotools/source/ucbhelper/tempfile.cxx b/unotools/source/ucbhelper/tempfile.cxx index c63287efe114..25c15920d52b 100644 --- a/unotools/source/ucbhelper/tempfile.cxx +++ b/unotools/source/ucbhelper/tempfile.cxx @@ -386,6 +386,9 @@ TempFile::TempFile(TempFile && other) noexcept : TempFile::~TempFile() { + // if we're going to delete this file, no point in flushing it when closing + if (pStream && bKillingFileEnabled && !aName.isEmpty()) + static_cast<SvFileStream*>(pStream.get())->SetDontFlushOnClose(true); pStream.reset(); if ( bKillingFileEnabled ) { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits