...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>
77 lines
2.2 KiB
C++
77 lines
2.2 KiB
C++
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
/*
|
|
* This file is part of the LibreOffice project.
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*
|
|
* This file incorporates work covered by the following license notice:
|
|
*
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
* with this work for additional information regarding copyright
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
* except in compliance with the License. You may obtain a copy of
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
*/
|
|
|
|
|
|
#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"
|
|
|
|
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;
|
|
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);
|
|
}
|
|
|
|
#endif
|
|
|
|
} }
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|