desktop/source/lib/init.cxx | 6 ++- include/vcl/builder.hxx | 10 +---- vcl/source/window/builder.cxx | 73 ++++++++++++++++++++++++++++++++---------- 3 files changed, 64 insertions(+), 25 deletions(-)
New commits: commit 5483721115884ac41778d9fc5c0f0461456f4dc7 Author: Michael Meeks <michael.me...@collabora.com> Date: Mon Mar 26 16:27:34 2018 +0100 lok: enable pre-loading with Vcl's builder Cache vclbuilder's loaded modules globally & simplify logic. Pre-populate that cache on preload for LOK vs. a somewhat inelegant pre-canned list of dialog libraries. Change-Id: I86d936862a41495fd37908f3ee7eb2e0c363d651 diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 4cb032500484..a9534de375e0 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -99,6 +99,8 @@ #include <unotools/datetime.hxx> #include <android/compatibility.hxx> #include <i18nlangtag/languagetag.hxx> +#include <vcl/builder.hxx> +#include <vcl/abstdlg.hxx> #include <app.hxx> @@ -3780,7 +3782,9 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char // 2) comphelper::setProcessServiceFactory(xSFactory); // 3) InitVCL() aService->initialize({css::uno::makeAny<OUString>("preload")}); - + // Force load some modules + VclBuilder::preload(); + VclAbstractDialogFactory::Create(); preloadData(); // Release Solar Mutex, lo_startmain thread should acquire it. diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx index e696c1dc04d8..12969fc2eac1 100644 --- a/include/vcl/builder.hxx +++ b/include/vcl/builder.hxx @@ -94,17 +94,13 @@ public: return m_sHelpRoot; } + /// Pre-loads all modules containing UI information + static void preload(); + private: VclBuilder(const VclBuilder&) = delete; VclBuilder& operator=(const VclBuilder&) = delete; - typedef std::map<OUString, std::unique_ptr<osl::Module>> ModuleMap; - - //We store these until the builder is deleted, that way we can use the - //ui-previewer on custom widgets and guarantee the modules they are from - //exist for the duration of the dialog - ModuleMap m_aModuleMap; - //If the toplevel window has any properties which need to be set on it, //but the toplevel is the owner of the builder, then its ctor //has not been completed during the building, so properties for it diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index da1e806d3a4d..cb3c5ae10152 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -13,6 +13,7 @@ #include <comphelper/processfactory.hxx> #include <osl/module.hxx> #include <sal/log.hxx> +#include <tools/solar.h> #include <unotools/resmgr.hxx> #include <vcl/builder.hxx> #include <vcl/button.hxx> @@ -1130,6 +1131,49 @@ void VclBuilder::cleanupWidgetOwnScrolling(vcl::Window *pScrollParent, vcl::Wind extern "C" { static void SAL_CALL thisModule() {} } #endif +// We store these forever, closing modules is non-ideal from a performance +// perspective, code pages will be freed up by the OS anyway if unused for +// a while in many cases, and this helps us pre-init. +typedef std::map<OUString, std::unique_ptr<osl::Module>> ModuleMap; +static ModuleMap g_aModuleMap; +static osl::Module g_aMergedLib; + +#ifndef SAL_DLLPREFIX +# define SAL_DLLPREFIX "" +#endif + +void VclBuilder::preload() +{ +#ifndef DISABLE_DYNLOADING + +#if ENABLE_MERGELIBS + g_aMergedLibs->loadRelative(&thisModule, SVLIBRARY("merged")); +#endif +// find -name '*ui*' | xargs grep 'class=".*lo-' | +// sed 's/.*class="//' | sed 's/-.*$//' | sort | uniq + static const char *aWidgetLibs[] = { + "sfxlo", "svtlo", "svxcorelo", "foruilo", + "vcllo", "svxlo", "cuilo", "swlo", + "swuilo", "sclo", "sdlo", "chartcontrollerlo", + "smlo", "scuilo", "basctllo", "sduilo", + "scnlo", "xsltdlglo", "pcrlo" // "dbulo" + }; + for (auto & lib : aWidgetLibs) + { + OUStringBuffer sModuleBuf; + sModuleBuf.append(SAL_DLLPREFIX); + sModuleBuf.append(OUString::createFromAscii(lib)); + sModuleBuf.append(SAL_DLLEXTENSION); + osl::Module* pModule = new osl::Module; + OUString sModule = sModuleBuf.makeStringAndClear(); + if (pModule->loadRelative(&thisModule, sModule)) + g_aModuleMap.insert(std::make_pair(sModule, std::unique_ptr<osl::Module>(pModule))); + else + delete pModule; + } +#endif // DISABLE_DYNLOADING +} + VclPtr<vcl::Window> VclBuilder::makeObject(vcl::Window *pParent, const OString &name, const OString &id, stringmap &rMap) { @@ -1618,33 +1662,28 @@ VclPtr<vcl::Window> VclBuilder::makeObject(vcl::Window *pParent, const OString & sal_Int32 nDelim = name.indexOf('-'); if (nDelim != -1) { + OUString sFunction(OStringToOUString(OString("make") + name.copy(nDelim+1), RTL_TEXTENCODING_UTF8)); #ifndef DISABLE_DYNLOADING OUStringBuffer sModuleBuf; sModuleBuf.append(SAL_DLLPREFIX); sModuleBuf.append(OStringToOUString(name.copy(0, nDelim), RTL_TEXTENCODING_UTF8)); sModuleBuf.append(SAL_DLLEXTENSION); -#endif - OUString sFunction(OStringToOUString(OString("make") + name.copy(nDelim+1), RTL_TEXTENCODING_UTF8)); -#ifndef DISABLE_DYNLOADING + OUString sModule = sModuleBuf.makeStringAndClear(); - ModuleMap::iterator aI = m_aModuleMap.find(sModule); - if (aI == m_aModuleMap.end()) + ModuleMap::iterator aI = g_aModuleMap.find(sModule); + if (aI == g_aModuleMap.end()) { osl::Module* pModule = new osl::Module; + bool ok = false; #if ENABLE_MERGELIBS - sModuleBuf.append(SAL_DLLPREFIX); - sModuleBuf.append("mergedlo"); - sModuleBuf.append(SAL_DLLEXTENSION); - OUString sMergedModule = sModuleBuf.makeStringAndClear(); - pModule->loadRelative(&thisModule, sMergedModule); - if (!pModule->getFunctionSymbol(sFunction)) - { - pModule->loadRelative(&thisModule, sModule); - } -#else - pModule->loadRelative(&thisModule, sModule); + if (!g_aMergedLib.is()) + g_aMergedLib->loadRelative(&thisModule, SVLIBRARY("merged")); + ok = g_aMergedLib->getFunctionSymbol(sFunction); #endif - aI = m_aModuleMap.insert(std::make_pair(sModule, std::unique_ptr<osl::Module>(pModule))).first; + if (!ok) + ok = pModule->loadRelative(&thisModule, sModule); + assert(ok && "bad module name in .ui"); + aI = g_aModuleMap.insert(std::make_pair(sModule, std::unique_ptr<osl::Module>(pModule))).first; } customMakeWidget pFunction = reinterpret_cast<customMakeWidget>(aI->second->getFunctionSymbol(sFunction)); #else _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits