aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleix Pol <aleixpol@kde.org>2021-07-05 00:37:28 +0200
committerAleix Pol <aleixpol@kde.org>2021-07-05 15:51:02 +0200
commite74f28482253890d1c7e74fa51f087cc3310ce60 (patch)
treea4b900cc5dbfdc84c74e34f73ab5f503479ca0f6 /src
parent57296d5c85a426918a634b15f814a7435b899d32 (diff)
downloadkconfig-e74f28482253890d1c7e74fa51f087cc3310ce60.tar.gz
kconfig-e74f28482253890d1c7e74fa51f087cc3310ce60.tar.bz2
Only query for existing config file when it's necessary
We are only interested in whether the file doesn't exist when it fails to open. This saves a stat on every successful config file parse.
Diffstat (limited to 'src')
-rw-r--r--src/core/kconfigini.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/core/kconfigini.cpp b/src/core/kconfigini.cpp
index c7861f66..fc6f34ec 100644
--- a/src/core/kconfigini.cpp
+++ b/src/core/kconfigini.cpp
@@ -68,20 +68,13 @@ KConfigBackend::ParseInfo KConfigIniBackend::parseConfig(const QByteArray &curre
// merge changes in the on-disk file with the changes in the KConfig object.
KConfigBackend::ParseInfo KConfigIniBackend::parseConfig(const QByteArray &currentLocale, KEntryMap &entryMap, ParseOptions options, bool merging)
{
- if (filePath().isEmpty() || !QFile::exists(filePath())) {
+ if (filePath().isEmpty()) {
return ParseOk;
}
- const QByteArray currentLanguage = currentLocale.split('_').first();
-
- bool bDefault = options & ParseDefaults;
- bool allowExecutableValues = options & ParseExpansions;
-
- QByteArray currentGroup("<default>");
-
QFile file(filePath());
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
- return ParseOpenError;
+ return file.exists() ? ParseOpenError : ParseOk;
}
QList<QByteArray> immutableGroups;
@@ -97,6 +90,11 @@ KConfigBackend::ParseInfo KConfigIniBackend::parseConfig(const QByteArray &curre
BufferFragment contents(buffer.data(), buffer.size());
unsigned int len = contents.length();
unsigned int startOfLine = 0;
+ const QByteArray currentLanguage = currentLocale.split('_').first();
+
+ QByteArray currentGroup("<default>");
+ bool bDefault = options & ParseDefaults;
+ bool allowExecutableValues = options & ParseExpansions;
// Reduce memory overhead by making use of implicit sharing
// This assumes that config files contain only a small amount of