summaryrefslogtreecommitdiff
path: root/unotools
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2022-10-22 09:28:16 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-10-22 10:34:21 +0200
commit9fd78b7421b5acefc8d0bde7cc103a045d79bd04 (patch)
treeaaeb1f053e4095d2ae33bedb6560b8d65cc39b87 /unotools
parente7be4bb5a3a388e844b718fa843c7a66b5c286d1 (diff)
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.grandin@collabora.co.uk>
Diffstat (limited to 'unotools')
-rw-r--r--unotools/source/ucbhelper/tempfile.cxx31
1 files changed, 30 insertions, 1 deletions
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();