[Libreoffice-commits] core.git: Branch 'feature/fixes18' - sal/osl

László Németh laszlo.nemeth at collabora.com
Tue Mar 15 00:37:49 UTC 2016


 sal/osl/w32/module.cxx |   24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

New commits:
commit a4572297e11ed50f30330fd3f7881b3b0322a33d
Author: László Németh <laszlo.nemeth at collabora.com>
Date:   Tue Mar 15 01:34:22 2016 +0100

    test optimized osl_loadModule
    
    Change-Id: I56d0da76c4270b360a99dc078ccfbbdd19c29d36

diff --git a/sal/osl/w32/module.cxx b/sal/osl/w32/module.cxx
index 5612391..7536d48 100644
--- a/sal/osl/w32/module.cxx
+++ b/sal/osl/w32/module.cxx
@@ -29,6 +29,8 @@
 #include <osl/file.h>
 #include <vector>
 
+#include <unordered_map>
+
 /*
     under WIN32, we use the void* oslModule
     as a WIN32 HANDLE (which is also a 32-bit value)
@@ -37,6 +39,16 @@
 /*****************************************************************************/
 /* osl_loadModule */
 /*****************************************************************************/
+
+
+typedef std::unordered_map<
+        rtl::OUString, oslModule,
+        rtl::OUStringHash, std::equal_to< rtl::OUString > > ModuleMapper;
+typedef std::pair< const OUString, const oslModule > ModuleValueType;
+
+
+static ModuleMapper modules;
+
 oslModule SAL_CALL osl_loadModule(rtl_uString *strModuleName, sal_Int32 /*nRtldMode*/ )
 {
     HMODULE h;
@@ -47,9 +59,14 @@ oslModule SAL_CALL osl_loadModule(rtl_uString *strModuleName, sal_Int32 /*nRtldM
     oslModule ret = 0;
     oslFileError    nError;
 
+    OUString modname ((sal_Unicode*)strModuleName->buffer, wcslen(strModuleName->buffer));
     SAL_INFO( "sal.osl", "osl_loadModule: " << OUString((sal_Unicode*)strModuleName->buffer, wcslen(strModuleName->buffer)) );
     OSL_ASSERT(strModuleName);
 
+    ModuleMapper::const_iterator iter = modules.find(modname);
+    if (iter != modules.end())
+        return iter->second;
+
     nError = osl_getSystemPathFromFileURL(strModuleName, &Module);
 
     if ( osl_File_E_None != nError )
@@ -60,7 +77,6 @@ oslModule SAL_CALL osl_loadModule(rtl_uString *strModuleName, sal_Int32 /*nRtldM
     if (h == NULL)
         h = LoadLibraryExW(reinterpret_cast<LPCWSTR>(Module->buffer), NULL,
                                   LOAD_WITH_ALTERED_SEARCH_PATH);
-
     //In case of long path names (\\?\c:\...) try to shorten the filename.
     //LoadLibrary cannot handle file names which exceed 260 letters.
     //In case the path is to long, the function will fail. However, the error
@@ -87,6 +103,7 @@ oslModule SAL_CALL osl_loadModule(rtl_uString *strModuleName, sal_Int32 /*nRtldM
     SetErrorMode(errorMode);
 #endif
 
+    modules.insert(ModuleValueType(modname, ret));
     return ret;
 }
 
@@ -144,6 +161,11 @@ osl_getModuleHandle(rtl_uString *pModuleName, oslModule *pResult)
 /*****************************************************************************/
 void SAL_CALL osl_unloadModule(oslModule Module)
 {
+    for(ModuleMapper::const_iterator iter = modules.begin(); iter != modules.end(); ++iter)
+        if (iter->second == Module) {
+            modules.erase(iter);
+            break;
+        }
     FreeLibrary((HMODULE)Module);
 }
 


More information about the Libreoffice-commits mailing list