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:⭐: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>
This commit is contained in:
parent
08ee6fb9f0
commit
ecf708e90d
@ -20,10 +20,15 @@
|
|||||||
|
|
||||||
#include <sal/config.h>
|
#include <sal/config.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
#include <osl/module.h>
|
#include <osl/module.h>
|
||||||
#include <osl/module.hxx>
|
#include <osl/module.hxx>
|
||||||
|
#include <rtl/malformeduriexception.hxx>
|
||||||
|
#include <rtl/uri.hxx>
|
||||||
#include <rtl/ustrbuf.hxx>
|
#include <rtl/ustrbuf.hxx>
|
||||||
#include <rtl/ustring.hxx>
|
#include <rtl/ustring.hxx>
|
||||||
|
#include <sal/log.hxx>
|
||||||
|
|
||||||
#include "loadmodule.hxx"
|
#include "loadmodule.hxx"
|
||||||
|
|
||||||
@ -32,14 +37,34 @@ namespace cppu { namespace detail {
|
|||||||
#ifndef DISABLE_DYNLOADING
|
#ifndef DISABLE_DYNLOADING
|
||||||
|
|
||||||
bool loadModule(osl::Module& rModule, OUString const & name) {
|
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 =
|
OUString b =
|
||||||
#if defined SAL_DLLPREFIX
|
#if defined SAL_DLLPREFIX
|
||||||
SAL_DLLPREFIX +
|
SAL_DLLPREFIX +
|
||||||
#endif
|
#endif
|
||||||
name +
|
name +
|
||||||
SAL_DLLEXTENSION;
|
SAL_DLLEXTENSION;
|
||||||
return rModule.loadRelative(
|
try {
|
||||||
reinterpret_cast< oslGenericFunction >(&loadModule),
|
b = rtl::Uri::convertRelToAbs(base, b);
|
||||||
|
} catch (rtl::MalformedUriException & e) {
|
||||||
|
SAL_INFO("cppu", "rtl::MalformedUriException <" << e.getMessage() << ">");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return rModule.load(
|
||||||
b,
|
b,
|
||||||
SAL_LOADMODULE_GLOBAL | SAL_LOADMODULE_LAZY);
|
SAL_LOADMODULE_GLOBAL | SAL_LOADMODULE_LAZY);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user