From e74f28482253890d1c7e74fa51f087cc3310ce60 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Mon, 5 Jul 2021 00:37:28 +0200 Subject: 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. --- src/core/kconfigini.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/core/kconfigini.cpp') 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 ¤tLocale, 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(""); - QFile file(filePath()); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - return ParseOpenError; + return file.exists() ? ParseOpenError : ParseOk; } QList 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(""); + 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 -- cgit v1.2.1