update dev300-m58
[ooovba.git] / applied_patches / 0197-speed-local-link.diff
blobaccb818176a03e6b93be91e2906d490616b43b31
1 Index: cppuhelper/source/shlib.cxx
2 ===================================================================
3 RCS file: /cvs/udk/cppuhelper/source/shlib.cxx,v
4 retrieving revision 1.30
5 diff -u -r1.30 shlib.cxx
6 --- cppuhelper/source/shlib.cxx 11 Apr 2008 11:37:03 -0000 1.30
7 +++ cppuhelper/source/shlib.cxx 27 Aug 2008 09:01:16 -0000
8 @@ -41,6 +41,8 @@
9 #include "uno/mapping.hxx"
10 #include "cppuhelper/factory.hxx"
11 #include "cppuhelper/shlib.hxx"
12 +#include "cppuhelper/bootstrap.hxx"
13 +#include <com/sun/star/lang/IllegalArgumentException.hpp>
15 #include "com/sun/star/beans/XPropertySet.hpp"
17 @@ -275,6 +277,141 @@
18 return out;
21 +#ifdef LINUX
23 +// This is a temporary hack until we can add this per
24 +// shlib annotation to services.rdb.
26 +static bool
27 +lcl_isWellKnownInternal(const OString &rLibName)
29 + // These are loaded at startup ...
30 + static const char *pLookup[] = {
31 + "behelper.uno.so",
32 + "configmgr2.uno.so",
33 + "deploymentli.uno.so",
34 + "fsstorage.uno.so",
35 + "gconfbe1.uno.so",
36 + "i18npool.uno.so",
37 + "introspection.uno.so",
38 + "ldapbe2.uno.so",
39 + "libanimcore.so",
40 + "libevtatt.so",
41 + "libfileacc.so",
42 + "libfilterconfig1.so",
43 + "libgcc3_uno.so",
44 + "liblocaledata_en.so",
45 + "liblocaledata_es.so",
46 + "liblocaledata_euro.so",
47 + "liblocaledata_others.so",
48 + "libmcnttype.so",
49 + "libpackage2.so",
50 + "libsrtrs1.so",
51 + "libucb1.so",
52 + "libucpfile1.so",
53 + "libxstor.so",
54 + "localebe1.uno.so",
55 + "implreg.uno.so",
56 + "nestedreg.uno.so",
57 + "regtypeprov.uno.so",
58 + "security.uno.so",
59 + "servicemgr.uno.so",
60 + "shlibloader.uno.so",
61 + "simplereg.uno.so",
62 + "typemgr.uno.so",
63 + "reflection.uno.so",
64 + "sax.uno.so",
65 + "stocservices.uno.so",
66 + "streams.uno.so",
67 + "sysmgr1.uno.so",
68 + "typeconverter.uno.so",
69 + "ucpgvfs1.uno.so",
70 + "uriproc.uno.so",
71 + NULL
72 + };
74 + // Perhaps do some cunning binary search ?
75 + for (int i = 0; pLookup[i] != NULL; i++) {
76 + bool match = rLibName.indexOf (pLookup[i]) > 0;
77 +// fprintf (stderr, "Match '%s' vs. '%s' : %d\n",
78 +// (const sal_Char *)rLibName, pLookup[i], match);
79 + if (match)
80 + return true;
81 + }
83 + return false;
86 +// bootstrap.cxx
87 +OUString const & get_this_libpath();
89 +// Amusing hack to get 40% win on linking / startup speedup:
90 +// Rational: we load all of OO.o's exception symbols in a single, global
91 +// shlib once first of all (RTLD_GLOBAL). This allows us to load all
92 +// subsequent components RTLD_LOCAL, their vague linkage symbols will
93 +// resolve in the global scope.
94 +static bool
95 +lcl_isInternalLibrary(OUString const & rLibName, OUString const & rPath)
97 + if (getenv ("OOO_DISABLE_INTERNAL"))
98 + return false;
100 +// fprintf (stderr, "Lib path '%s' ",
101 +// (const sal_Char *)rtl::OUStringToOString(rPath, RTL_TEXTENCODING_ASCII_US));
102 +// fprintf (stderr, "name '%s' - test:\n",
103 +// (const sal_Char *)rtl::OUStringToOString(rLibName, RTL_TEXTENCODING_ASCII_US));
105 + bool bIsInternal = false;
107 + // Is this an internal library ?
108 + if (rPath.getLength() > 0 && rPath != get_this_libpath())
110 +// fprintf (stderr, "Lib path '%s' - not internal!\n",
111 +// (const sal_Char *)rtl::OUStringToOString(rPath, RTL_TEXTENCODING_ASCII_US));
112 + return false;
115 + sal_Int32 nUpd = SUPD;
116 + OUString aIntSuffix = OUSTR("li.so");
117 + if (rLibName.indexOf (aIntSuffix) > 0)
118 + bIsInternal = true;
120 + if (!bIsInternal)
121 + bIsInternal = lcl_isWellKnownInternal(
122 + OUStringToOString(rLibName, RTL_TEXTENCODING_UTF8));
124 + // If internal - load the exception type library RTLD_GLOBAL first
125 + static bool bHaveLoadedExcepts = false;
126 + if (bIsInternal && !bHaveLoadedExcepts)
128 + rtl::OUString aExceptTmpl = rtl::OUString::createFromAscii("vnd.sun.star.expand:$OOO_BASE_DIR/program/libexlink") + aIntSuffix;
129 + rtl::OUString aExceptName;
130 + try
132 + aExceptName = cppu::bootstrap_expandUri( aExceptTmpl );
134 + catch ( ::com::sun::star::lang::IllegalArgumentException & e ) {}
135 + oslModule nExceptLib = osl_loadModule(aExceptName.pData,
136 + SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL);
137 + if (nExceptLib != NULL) {
138 + bHaveLoadedExcepts = true;
139 +// fprintf (stderr, "Loaded'%s'\n",
140 +// (const sal_Char *)rtl::OUStringToOString(aExceptName, RTL_TEXTENCODING_ASCII_US));
141 + } else {
142 + bIsInternal = false;
143 +// fprintf (stderr, "Failed to load'%s'\n",
144 +// (const sal_Char *)rtl::OUStringToOString(aExceptName, RTL_TEXTENCODING_ASCII_US));
148 +// fprintf (stderr, "Lib name '%s' %d %d\n",
149 +// (const sal_Char *)rtl::OUStringToOString(rLibName, RTL_TEXTENCODING_ASCII_US),
150 +// bIsInternal, bHaveLoadedExcepts);
152 + return bIsInternal;
154 +#endif
156 //==============================================================================
157 static OUString getLibEnv(OUString const & aModulePath,
158 oslModule lib,
159 @@ -346,9 +483,17 @@
160 aModulePath,
161 Reference< XInterface >() );
164 + sal_Int32 nFlags = SAL_LOADMODULE_LAZY;
165 +#ifdef LINUX
166 + if (!lcl_isInternalLibrary (rLibName, rPath))
167 + nFlags |= SAL_LOADMODULE_GLOBAL;
168 +// else - faster local only binding
169 +#else
170 + nFlags |= SAL_LOADMODULE_GLOBAL;
171 +#endif
173 - oslModule lib = osl_loadModule(
174 - aModulePath.pData, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL );
175 + oslModule lib = osl_loadModule(aModulePath.pData, nFlags);
176 if (! lib)
178 throw loader::CannotActivateFactoryException(