summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2021-06-20 20:19:28 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-06-21 14:27:53 +0200
commit46d6942bc16fb291f37b0700bb531a3e0d2d11f6 (patch)
tree846a6b4e8f3ec582966e52faae5cc808e6db4504 /sal
parent8bf44b9cdceb7926fe52ef0bd4a38af24e7c700a (diff)
tdf#135316 add small cache to rtl_bootstrap_args_open
Filesystem access is quite expensive on Windows, so add a small cache for the filepath/name normalisation. This takes my load time from 19s to 18s Change-Id: I4410d066b8a4d2fd2eb746a5dd8f4ee763a8aa3e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117549 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sal')
-rw-r--r--sal/rtl/bootstrap.cxx33
1 files changed, 24 insertions, 9 deletions
diff --git a/sal/rtl/bootstrap.cxx b/sal/rtl/bootstrap.cxx
index 9aa3546a5ca7..afb80dcd66cb 100644
--- a/sal/rtl/bootstrap.cxx
+++ b/sal/rtl/bootstrap.cxx
@@ -37,6 +37,7 @@
#include <rtl/malformeduriexception.hxx>
#include <rtl/uri.hxx>
#include <sal/log.hxx>
+#include <o3tl/lru_map.hxx>
#include <vector>
#include <algorithm>
@@ -588,21 +589,35 @@ bootstrap_map_t bootstrap_map;
rtlBootstrapHandle SAL_CALL rtl_bootstrap_args_open(rtl_uString * pIniName)
{
- OUString iniName( pIniName );
+ static o3tl::lru_map<OUString,OUString> fileUrlLookupCache(16);
+
+ OUString originalIniName( pIniName );
+ OUString iniName;
+
+ osl::ResettableMutexGuard guard(osl::Mutex::getGlobalMutex());
+ auto cacheIt = fileUrlLookupCache.find(originalIniName);
+ bool foundInCache = cacheIt != fileUrlLookupCache.end();
+ if (foundInCache)
+ iniName = cacheIt->second;
+ guard.clear();
// normalize path
- FileStatus status(osl_FileStatus_Mask_FileURL);
- DirectoryItem dirItem;
- if (DirectoryItem::get(iniName, dirItem) != DirectoryItem::E_None ||
- dirItem.getFileStatus(status) != DirectoryItem::E_None)
+ if (!foundInCache)
{
- return nullptr;
+ FileStatus status(osl_FileStatus_Mask_FileURL);
+ DirectoryItem dirItem;
+ if (DirectoryItem::get(originalIniName, dirItem) != DirectoryItem::E_None ||
+ dirItem.getFileStatus(status) != DirectoryItem::E_None)
+ {
+ return nullptr;
+ }
+ iniName = status.getFileURL();
}
- iniName = status.getFileURL();
-
+ guard.reset();
+ if (!foundInCache)
+ fileUrlLookupCache.insert({originalIniName, iniName});
Bootstrap_Impl * that;
- osl::ResettableMutexGuard guard(osl::Mutex::getGlobalMutex());
auto iFind(bootstrap_map.find(iniName));
if (iFind == bootstrap_map.end())
{