[Libreoffice-commits] core.git: sal/rtl

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Mon Jun 21 12:28:29 UTC 2021


 sal/rtl/bootstrap.cxx |   33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)

New commits:
commit 46d6942bc16fb291f37b0700bb531a3e0d2d11f6
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Sun Jun 20 20:19:28 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon Jun 21 14:27:53 2021 +0200

    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 at collabora.co.uk>

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())
     {


More information about the Libreoffice-commits mailing list