summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2019-11-08 12:45:26 +0100
committerStephan Bergmann <sbergman@redhat.com>2019-11-08 14:19:10 +0100
commitecf708e90d96d5a72491e40fa679c47e66eebd49 (patch)
tree8e9721dfaa6680119a2605ffca5b1414d9e3d7a6
parent08ee6fb9f0f50aaf9bb9d3dfe26f610d9bbbc2ab (diff)
Avoid repeated calls cppu::detail::loadModule -> osl_getModuleURLFromAddress
...where the latter are reportedly expensive. Both <https://gerrit.libreoffice.org/#/c/75162/> "tdf#121740 related, cache external mapping in cppu::loadExternal" and <https://gerrit.libreoffice.org/#/c/82261/> "tdf#121740 add cache to win osl_getModuleURLFromAddress" attempted to reduce the costs observed when loading one specific document by introducing caches below cppu::detail::loadModule's call to osl::Module::loadRelative. On the other hand, this change reduces the number of calls to osl_getModuleURLFromAddress by computing the base URI in cppu::detail::loadModule only once. For my local Linux --enable-dbgutil build, for `instdir/program/soffice '109340 class14.ppt'` and then exiting LO again (with the document attached at <https://bugs.documentfoundation.org/show_bug.cgi?id=121740#c0>), this reduces the number of calls to osl_getModuleURLFromAddress from 3775 to 22. (Many of those calls originated from cppu::getCaughtException or cppu::throwException, as in osl_getModuleURLFromAddress osl_getModuleURLFromFunctionAddress osl::Module::getUrlFromAddress osl_loadModuleRelative osl::Module::loadRelative cppu::detail::loadModule cppu::loadModule cppu::loadExternalMapping uno_getMapping com::sun::star::uno::Mapping::Mapping cppu::throwException .) Unfortunately, this needs to duplicate functionality from osl_loadModuleRelative (sal/osl/all/loadmodulerelative.cxx) somewhat, as the stable SAL interface only offers functionality to load relative to a given function, not relative to a given base URI. (And extending the stable SAL interface for this one use is not worth the maintenance costs.) Change-Id: Ib58814136d11c67d1419b0224d12e30bb710e613 Reviewed-on: https://gerrit.libreoffice.org/82290 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r--cppu/source/uno/loadmodule.cxx29
1 files changed, 27 insertions, 2 deletions
diff --git a/cppu/source/uno/loadmodule.cxx b/cppu/source/uno/loadmodule.cxx
index 9e970b754536..359227b24206 100644
--- a/cppu/source/uno/loadmodule.cxx
+++ b/cppu/source/uno/loadmodule.cxx
@@ -20,10 +20,15 @@
#include <sal/config.h>
+#include <cassert>
+
#include <osl/module.h>
#include <osl/module.hxx>
+#include <rtl/malformeduriexception.hxx>
+#include <rtl/uri.hxx>
#include <rtl/ustrbuf.hxx>
#include <rtl/ustring.hxx>
+#include <sal/log.hxx>
#include "loadmodule.hxx"
@@ -32,14 +37,34 @@ namespace cppu { namespace detail {
#ifndef DISABLE_DYNLOADING
bool loadModule(osl::Module& rModule, OUString const & name) {
+ static OUString base = [] {
+ OUString url;
+ if (!osl::Module::getUrlFromAddress(
+ reinterpret_cast<oslGenericFunction>(&loadModule), url))
+ {
+ SAL_WARN("cppu", "osl::Module::getUrlFromAddress failed");
+ return OUString();
+ }
+ assert(!url.isEmpty());
+ return url;
+ }();
+ if (base.isEmpty()) {
+ SAL_INFO("cppu", "osl::Module::getUrlFromAddress had failed");
+ return false;
+ }
OUString b =
#if defined SAL_DLLPREFIX
SAL_DLLPREFIX +
#endif
name +
SAL_DLLEXTENSION;
- return rModule.loadRelative(
- reinterpret_cast< oslGenericFunction >(&loadModule),
+ try {
+ b = rtl::Uri::convertRelToAbs(base, b);
+ } catch (rtl::MalformedUriException & e) {
+ SAL_INFO("cppu", "rtl::MalformedUriException <" << e.getMessage() << ">");
+ return false;
+ }
+ return rModule.load(
b,
SAL_LOADMODULE_GLOBAL | SAL_LOADMODULE_LAZY);
}