Reduce open and stat system calls for QSettings
The patch moves the global static QSettings object from QLibrary to QCoreApplication and reduces a few stat and open calls. Without the patch, a large Trolltech.conf was pushed out of the unused settings cache during startup, meaning Trolltech.conf was parsed more than once. Reviewed-by: Liang Qi (cherry picked from commit 31ef8fa6abc2ea23c6f0a996b36494d88aafb0b5)
This commit is contained in:
parent
d454d69408
commit
4b75ceea08
@ -981,23 +981,6 @@ QStringList QSettingsPrivate::splitArgs(const QString &s, int idx)
|
||||
// ************************************************************************
|
||||
// QConfFileSettingsPrivate
|
||||
|
||||
/*
|
||||
If we don't have the permission to read the file, returns false.
|
||||
If the file doesn't exist, returns true.
|
||||
*/
|
||||
static bool checkAccess(const QString &name)
|
||||
{
|
||||
QFileInfo fileInfo(name);
|
||||
|
||||
if (fileInfo.exists()) {
|
||||
QFile file(name);
|
||||
// if the file exists but we can't open it, report an error
|
||||
return file.open(QFile::ReadOnly);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void QConfFileSettingsPrivate::initFormat()
|
||||
{
|
||||
extension = (format == QSettings::NativeFormat) ? QLatin1String(".conf") : QLatin1String(".ini");
|
||||
@ -1026,18 +1009,13 @@ void QConfFileSettingsPrivate::initFormat()
|
||||
|
||||
void QConfFileSettingsPrivate::initAccess()
|
||||
{
|
||||
bool readAccess = false;
|
||||
if (confFiles[spec]) {
|
||||
readAccess = checkAccess(confFiles[spec]->name);
|
||||
if (format > QSettings::IniFormat) {
|
||||
if (!readFunc)
|
||||
readAccess = false;
|
||||
setStatus(QSettings::AccessError);
|
||||
}
|
||||
}
|
||||
|
||||
if (!readAccess)
|
||||
setStatus(QSettings::AccessError);
|
||||
|
||||
sync(); // loads the files the first time
|
||||
}
|
||||
|
||||
@ -1432,7 +1410,7 @@ void QConfFileSettingsPrivate::syncConfFile(int confFileNo)
|
||||
We can often optimize the read-only case, if the file on disk
|
||||
hasn't changed.
|
||||
*/
|
||||
if (readOnly) {
|
||||
if (readOnly && confFile->size > 0) {
|
||||
QFileInfo fileInfo(confFile->name);
|
||||
if (confFile->size == fileInfo.size() && confFile->timeStamp == fileInfo.lastModified())
|
||||
return;
|
||||
@ -1455,6 +1433,9 @@ void QConfFileSettingsPrivate::syncConfFile(int confFileNo)
|
||||
if (!file.isOpen())
|
||||
file.open(QFile::ReadOnly);
|
||||
|
||||
if (!createFile && !file.isOpen())
|
||||
setStatus(QSettings::AccessError);
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
HANDLE readSemaphore = 0;
|
||||
HANDLE writeSemaphore = 0;
|
||||
|
@ -270,6 +270,8 @@ bool QCoreApplicationPrivate::is_app_closing = false;
|
||||
Q_CORE_EXPORT bool qt_locale_initialized = false;
|
||||
|
||||
|
||||
QSettings *QCoreApplicationPrivate::trolltechConf = 0;
|
||||
|
||||
Q_CORE_EXPORT uint qGlobalPostedEventsCount()
|
||||
{
|
||||
QThreadData *currentThreadData = QThreadData::current();
|
||||
@ -371,6 +373,9 @@ QCoreApplicationPrivate::~QCoreApplicationPrivate()
|
||||
threadData->postEventList.recursion = 0;
|
||||
threadData->quitNow = false;
|
||||
}
|
||||
|
||||
delete trolltechConf;
|
||||
trolltechConf = 0;
|
||||
}
|
||||
|
||||
void QCoreApplicationPrivate::createEventDispatcher()
|
||||
@ -692,6 +697,13 @@ void QCoreApplication::init()
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
Create an instance of Trolltech.conf. This ensures that the settings will not
|
||||
be thrown out of QSetting's cache for unused settings.
|
||||
*/
|
||||
d->trolltechConf = new QSettings(QSettings::UserScope, QLatin1String("Trolltech"));
|
||||
|
||||
qt_startup_hook();
|
||||
}
|
||||
|
||||
|
@ -55,6 +55,7 @@
|
||||
|
||||
#include "QtCore/qcoreapplication.h"
|
||||
#include "QtCore/qtranslator.h"
|
||||
#include "QtCore/qsettings.h"
|
||||
#include "private/qobject_p.h"
|
||||
|
||||
#ifdef Q_OS_SYMBIAN
|
||||
@ -141,6 +142,7 @@ public:
|
||||
#if defined(QT3_SUPPORT)
|
||||
static bool useQt3Support;
|
||||
#endif
|
||||
static QSettings *trolltechConf;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -52,6 +52,7 @@
|
||||
#include <qmap.h>
|
||||
#include <qsettings.h>
|
||||
#include <qdatetime.h>
|
||||
#include <private/qcoreapplication_p.h>
|
||||
#ifdef Q_OS_MAC
|
||||
# include <private/qcore_mac_p.h>
|
||||
#endif
|
||||
@ -408,12 +409,6 @@ static bool qt_unix_query(const QString &library, uint *version, bool *debug, QB
|
||||
typedef QMap<QString, QLibraryPrivate*> LibraryMap;
|
||||
|
||||
struct LibraryData {
|
||||
LibraryData() : settings(0) { }
|
||||
~LibraryData() {
|
||||
delete settings;
|
||||
}
|
||||
|
||||
QSettings *settings;
|
||||
LibraryMap libraryMap;
|
||||
QSet<QLibraryPrivate*> loadedLibs;
|
||||
};
|
||||
@ -711,11 +706,7 @@ bool QLibraryPrivate::isPlugin(QSettings *settings)
|
||||
QStringList reg;
|
||||
#ifndef QT_NO_SETTINGS
|
||||
if (!settings) {
|
||||
settings = libraryData()->settings;
|
||||
if (!settings) {
|
||||
settings = new QSettings(QSettings::UserScope, QLatin1String("Trolltech"));
|
||||
libraryData()->settings = settings;
|
||||
}
|
||||
settings = QCoreApplicationPrivate::trolltechConf;
|
||||
}
|
||||
reg = settings->value(regkey).toStringList();
|
||||
#endif
|
||||
|
@ -55,6 +55,9 @@
|
||||
#endif // QT_NO_XCURSOR
|
||||
|
||||
#ifndef QT_NO_XFIXES
|
||||
#ifndef Status
|
||||
#define Status int
|
||||
#endif
|
||||
# include <X11/extensions/Xfixes.h>
|
||||
#endif // QT_NO_XFIXES
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user