From bf417fc0347467092dfd12a72ed8177524b473d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Fri, 21 Aug 2009 11:12:43 +0200 Subject: Speed up plugin loading by not constructing a new QSettings each time. This should benefit the platforms with slow QSettings, esp. Linux. Task-number: 243398 Reviewed-by: brad --- src/corelib/plugin/qlibrary.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index ea8882f..f784622 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -416,7 +416,23 @@ static bool qt_unix_query(const QString &library, uint *version, bool *debug, QB #endif // Q_OS_UNIX && !Q_OS_MAC && !defined(QT_NO_PLUGIN_CHECK) typedef QMap LibraryMap; -Q_GLOBAL_STATIC(LibraryMap, libraryMap) + +struct LibraryData { + LibraryData() : settings(0) { } + ~LibraryData() { + delete settings; + } + + QSettings *settings; + LibraryMap libraryMap; +}; + +Q_GLOBAL_STATIC(LibraryData, libraryData) + +static LibraryMap *libraryMap() +{ + return &(libraryData()->libraryMap); +} QLibraryPrivate::QLibraryPrivate(const QString &canonicalFileName, const QString &version) :pHnd(0), fileName(canonicalFileName), fullVersion(version), instance(0), qt_version(0), @@ -597,10 +613,12 @@ bool QLibraryPrivate::isPlugin(QSettings *settings) .arg(fileName); QStringList reg; #ifndef QT_NO_SETTINGS - bool madeSettings = false; if (!settings) { - settings = new QSettings(QSettings::UserScope, QLatin1String("Trolltech")); - madeSettings = true; + settings = libraryData()->settings; + if (!settings) { + settings = new QSettings(QSettings::UserScope, QLatin1String("Trolltech")); + libraryData()->settings = settings; + } } reg = settings->value(regkey).toStringList(); #endif @@ -679,10 +697,6 @@ bool QLibraryPrivate::isPlugin(QSettings *settings) settings->setValue(regkey, queried); #endif } -#ifndef QT_NO_SETTINGS - if (madeSettings) - delete settings; -#endif if (!success) { if (errorString.isEmpty()){ -- cgit v0.12