summaryrefslogtreecommitdiffstats
path: root/src/corelib/plugin/qlibrary_unix.cpp
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2012-07-18 13:12:46 +0100
committerQt by Nokia <qt-info@nokia.com>2012-07-23 17:56:13 +0200
commit0026b80cd2a484ad9d685ff5a4f89e6c9815f913 (patch)
treeb62c9edd46c777e24aedfe2b8b7a2b46594e2f5c /src/corelib/plugin/qlibrary_unix.cpp
parentb1829403408aebdf62b61dcefdb96b0457b9bd3e (diff)
Improve the loading performance of QLibrary
If an absolute path is specified we try that first. Otherwise we first try the most likely system-specific format (e.g. libfoo.so) on Unix. This improves performance especially on systems with slow flash devices. For example, prior to this commit loading the Xcursor library (in the xcb plugin) results in attempts to dlopen: "Xcursor" "Xcursor.so.1" "libXcursor" "libXcursor.so.1" With this commit this is reduced to a single attempt of: "libXcursor.so.1" Plugin loading uses absolute paths with QLibrary so there is no performance penalty for plugins with this commit. This is however a behavioural change with respect to Qt4 but one that I believe is justified and wanted. Change-Id: I7813afa335f9bf515e87934c2f8f97888818c69c Reviewed-by: Lars Knoll <lars.knoll@nokia.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Diffstat (limited to 'src/corelib/plugin/qlibrary_unix.cpp')
-rw-r--r--src/corelib/plugin/qlibrary_unix.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/corelib/plugin/qlibrary_unix.cpp b/src/corelib/plugin/qlibrary_unix.cpp
index abfbeb25d4..0ad9f690d5 100644
--- a/src/corelib/plugin/qlibrary_unix.cpp
+++ b/src/corelib/plugin/qlibrary_unix.cpp
@@ -93,9 +93,8 @@ bool QLibraryPrivate::load_sys()
else
path += QLatin1Char('/');
- // The first filename we want to attempt to load is the filename as the callee specified.
- // Thus, the first attempt we do must be with an empty prefix and empty suffix.
- QStringList suffixes(QLatin1String("")), prefixes(QLatin1String(""));
+ QStringList suffixes;
+ QStringList prefixes;
if (pluginState != IsAPlugin) {
prefixes << QLatin1String("lib");
#if defined(Q_OS_HPUX)
@@ -185,6 +184,18 @@ bool QLibraryPrivate::load_sys()
}
#endif
#endif // QT_HPUX_LD
+
+ // If the filename is an absolute path then we want to try that first as it is most likely
+ // what the callee wants. If we have been given a non-absolute path then lets try the
+ // native library name first to avoid unnecessary calls to dlopen().
+ if (fsEntry.isAbsolute()) {
+ suffixes.prepend(QString());
+ prefixes.prepend(QString());
+ } else {
+ suffixes.append(QString());
+ prefixes.append(QString());
+ }
+
bool retry = true;
for(int prefix = 0; retry && !pHnd && prefix < prefixes.size(); prefix++) {
for(int suffix = 0; retry && !pHnd && suffix < suffixes.size(); suffix++) {