unotools/source/ucbhelper/tempfile.cxx |   31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

New commits:
commit 9fd78b7421b5acefc8d0bde7cc103a045d79bd04
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Sat Oct 22 09:28:16 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sat Oct 22 10:34:21 2022 +0200

    tdf#133767 speed up temp file creation
    
    Use a GUID so we can avoid needing to check if the filename
    already exists.
    Shaves 2% off the export time.
    
    Change-Id: Id08104b187365eb35c84639254263329a8218a41
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141664
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/unotools/source/ucbhelper/tempfile.cxx 
b/unotools/source/ucbhelper/tempfile.cxx
index f55c421a0291..61ef2d247c01 100644
--- a/unotools/source/ucbhelper/tempfile.cxx
+++ b/unotools/source/ucbhelper/tempfile.cxx
@@ -33,6 +33,7 @@
 #include <osl/file.hxx>
 #include <tools/time.hxx>
 #include <tools/debug.hxx>
+#include <tools/Guid.hxx>
 #include <comphelper/DirectoryHelper.hxx>
 
 #ifdef UNX
@@ -350,6 +351,34 @@ static OUString CreateTempName_Impl( const OUString* 
pParent, bool bKeep, bool b
                            false, false);
 }
 
+static OUString CreateTempNameFast()
+{
+    OUString aEyeCatcher = "lu";
+#ifdef UNX
+#ifdef DBG_UTIL
+    const char* eye = getenv("LO_TESTNAME");
+    if(eye)
+    {
+        aEyeCatcher = OUString(eye, strlen(eye), RTL_TEXTENCODING_ASCII_US);
+    }
+#else
+    static const pid_t pid = getpid();
+    static const OUString aPidString = OUString::number(pid);
+    aEyeCatcher += aPidString;
+#endif
+#elif defined(_WIN32)
+    static const int pid = _getpid();
+    static const OUString aPidString = OUString::number(pid);
+    aEyeCatcher += aPidString;
+#endif
+
+    OUString aName = ConstructTempDir_Impl( /*pParent*/nullptr, 
/*bCreateParentDirs*/false ) + aEyeCatcher;
+
+    tools::Guid aGuid(tools::Guid::Generate);
+
+    return aName + aGuid.getOUString() + ".tmp" ;
+}
+
 OUString CreateTempName()
 {
     OUString aName(CreateTempName_Impl( nullptr, false ));
@@ -379,7 +408,7 @@ SvStream* TempFileFast::GetStream( StreamMode eMode )
 {
     if (!mxStream)
     {
-        OUString aName = CreateTempName_Impl( /*pParent*/nullptr, 
/*bKeep*/true, /*bDirectory*/false );
+        OUString aName = CreateTempNameFast();
         mxStream.reset(new SvFileStream(aName, eMode | StreamMode::TEMPORARY));
     }
     return mxStream.get();

Reply via email to