[Libreoffice-commits] core.git: include/tools tools/source unotools/source
include/tools/stream.hxx |5 +++-- tools/source/stream/strmwnt.cxx|2 ++ unotools/source/ucbhelper/tempfile.cxx |9 + 3 files changed, 14 insertions(+), 2 deletions(-) New commits: commit 1ea0ea19f1dc13c4191ab9d4222adfd2579b802c Author: Noel Grandin AuthorDate: Mon Oct 24 09:06:42 2022 +0200 Commit: Noel Grandin CommitDate: Mon Oct 24 10:10:54 2022 +0200 tdf#133768 speed up temp file creation Use DELETE_ON_CLOSE attribute, so we can avoid calling osl_removeFile. Shaves 5% off the export time. Change-Id: I4fef8f181ef7a92c4805cc5996c3a17800a22602 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141718 Tested-by: Noel Grandin Reviewed-by: Noel Grandin diff --git a/include/tools/stream.hxx b/include/tools/stream.hxx index c56a3d44cef6..b141c8ed44f7 100644 --- a/include/tools/stream.hxx +++ b/include/tools/stream.hxx @@ -50,8 +50,9 @@ enum class StreamMode { // file i/o 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) +COPY_ON_SYMLINK = 0x0010, ///< copy-on-write for symlinks (Unix-only) TEMPORARY= 0x0020, ///< temporary file attribute (Windows-only) +DELETE_ON_CLOSE = 0x0040, ///< only for temporary files (Windows-only) // sharing options SHARE_DENYNONE = 0x0100, SHARE_DENYREAD = 0x0200, // overrides denynone @@ -65,7 +66,7 @@ enum class StreamMode { }; namespace o3tl { -template<> struct typed_flags : is_typed_flags {}; +template<> struct typed_flags : is_typed_flags {}; } #define STREAM_SEEK_TO_BEGIN0L diff --git a/tools/source/stream/strmwnt.cxx b/tools/source/stream/strmwnt.cxx index 4ea9c7eb1d42..f88cbe307606 100644 --- a/tools/source/stream/strmwnt.cxx +++ b/tools/source/stream/strmwnt.cxx @@ -304,6 +304,8 @@ void SvFileStream::Open( const OUString& rFilename, StreamMode nMode ) if ( nMode & StreamMode::TEMPORARY ) nAttributes |= FILE_ATTRIBUTE_TEMPORARY; +if ( nMode & StreamMode::DELETE_ON_CLOSE ) +nAttributes |= FILE_FLAG_DELETE_ON_CLOSE; pInstanceData->hFile = CreateFileW( o3tl::toW(aFilename.getStr()), diff --git a/unotools/source/ucbhelper/tempfile.cxx b/unotools/source/ucbhelper/tempfile.cxx index 61ef2d247c01..efeb872b5d6d 100644 --- a/unotools/source/ucbhelper/tempfile.cxx +++ b/unotools/source/ucbhelper/tempfile.cxx @@ -409,7 +409,11 @@ SvStream* TempFileFast::GetStream( StreamMode eMode ) if (!mxStream) { OUString aName = CreateTempNameFast(); +#ifdef _WIN32 +mxStream.reset(new SvFileStream(aName, eMode | StreamMode::TEMPORARY | StreamMode::DELETE_ON_CLOSE)); +#else mxStream.reset(new SvFileStream(aName, eMode | StreamMode::TEMPORARY)); +#endif } return mxStream.get(); } @@ -420,8 +424,13 @@ void TempFileFast::CloseStream() { OUString aName = mxStream->GetFileName(); mxStream.reset(); +#ifdef _WIN32 +// On Windows, the file is opened with FILE_FLAG_DELETE_ON_CLOSE, so it will delete as soon as the handle closes. +// On other platforms, we need to explicitly delete it. +#else if (!aName.isEmpty() && (osl::FileBase::getFileURLFromSystemPath(aName, aName) == osl::FileBase::E_None)) File::remove(aName); +#endif } }
[Libreoffice-commits] core.git: include/tools tools/source unotools/source
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 9815bf197c27afdfeccf967898c3a000bcf7b256 Author: Noel Grandin AuthorDate: Mon Jun 21 12:54:29 2021 +0200 Commit: Noel Grandin CommitDate: Wed Jun 23 14:29:57 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 diff --git a/include/tools/stream.hxx b/include/tools/stream.hxx index f99b09955368..e99d41c8ac45 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 boolbIsOpen; +boolmbDontFlushOnClose; ///< used to avoid flushing when closing temporary files SvFileStream (const SvFileStream&) = delete; SvFileStream & operator= (const SvFileStream&) = delete; @@ -612,6 +613,7 @@ public: boolIsOpen() const { return bIsOpen; } const OUString& GetFileName() const { return aFilename; } +voidSetDontFlushOnClose(bool b) { mbDontFlushOnClose = b; } }; // MemoryStream diff --git a/tools/source/stream/strmunx.cxx b/tools/source/stream/strmunx.cxx index 0b745e69b140..e034f53ac33b 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 ); } @@ -457,7 +459,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(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
[Libreoffice-commits] core.git: include/tools tools/source unotools/source
include/tools/stream.hxx |3 ++- tools/source/stream/strmwnt.cxx|7 ++- unotools/source/ucbhelper/tempfile.cxx |2 +- 3 files changed, 9 insertions(+), 3 deletions(-) New commits: commit 27960861a66d13a3f0bb3ff8503bc9fdb53745da Author: Noel Grandin AuthorDate: Tue Feb 18 18:54:43 2020 +0200 Commit: Noel Grandin CommitDate: Wed Feb 19 09:14:31 2020 +0100 use FILE_ATTRIBUTE_TEMPORARY on Windows for temp files which acts as a hint to the OS that these files do not need persistent storage. If there is sufficient system RAM, these files will never even hit disk. Change-Id: I25b83aad67fda58ec39cead8bd1eb038892d3cde Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88124 Tested-by: Jenkins Reviewed-by: Noel Grandin diff --git a/include/tools/stream.hxx b/include/tools/stream.hxx index 0f17c37c4958..2e8fbc6771b5 100644 --- a/include/tools/stream.hxx +++ b/include/tools/stream.hxx @@ -48,6 +48,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) // sharing options SHARE_DENYNONE = 0x0100, SHARE_DENYREAD = 0x0200, // overrides denynone @@ -61,7 +62,7 @@ enum class StreamMode { }; namespace o3tl { -template<> struct typed_flags : is_typed_flags {}; +template<> struct typed_flags : is_typed_flags {}; } #define STREAM_SEEK_TO_BEGIN0L diff --git a/tools/source/stream/strmwnt.cxx b/tools/source/stream/strmwnt.cxx index 23fa71526447..d85ce3a0c372 100644 --- a/tools/source/stream/strmwnt.cxx +++ b/tools/source/stream/strmwnt.cxx @@ -300,13 +300,18 @@ void SvFileStream::Open( const OUString& rFilename, StreamMode nMode ) nOpenAction = OPEN_EXISTING; } +DWORD nAttributes = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS; + +if ( nMode & StreamMode::TEMPORARY ) +nAttributes |= FILE_ATTRIBUTE_TEMPORARY; + pInstanceData->hFile = CreateFileW( o3tl::toW(aFilename.getStr()), nAccessMode, nShareMode, nullptr, nOpenAction, -FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, +nAttributes, nullptr ); diff --git a/unotools/source/ucbhelper/tempfile.cxx b/unotools/source/ucbhelper/tempfile.cxx index afda12972ac0..f6d66bdc33b6 100644 --- a/unotools/source/ucbhelper/tempfile.cxx +++ b/unotools/source/ucbhelper/tempfile.cxx @@ -420,7 +420,7 @@ SvStream* TempFile::GetStream( StreamMode eMode ) if (!pStream) { if (!aName.isEmpty()) -pStream.reset(new SvFileStream(aName, eMode)); +pStream.reset(new SvFileStream(aName, eMode | StreamMode::TEMPORARY)); else pStream.reset(new SvMemoryStream(nullptr, 0, eMode)); } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits