aboutsummaryrefslogtreecommitdiff
path: root/src/core/kconfig.cpp
AgeCommit message (Collapse)Author
2022-01-02Extract isNonDeletedKey() helper functionIgor Kushnir
The eliminated duplication of the composite condition was error-prone and less readable.
2022-01-02Look for entries with common group prefix in entryMap's subrangeIgor Kushnir
entryMap is ordered by the group name first. So there is no need to iterate over the entire map to process entries whose group names start with some prefix. Find the group name prefix's lower bound and iterate over the proper subrange instead. This should be much faster, especially if the subrange's size is much less than the entryMap's size. Adjust isGroupOrSubGroupMatch() helper function to assert the extracted startsWith() condition instead of rechecking it. Pass KEntryMapConstIterator in place of the group name to this function in order to simplify its callers' code. Reuse this helper function in KConfigPrivate::copyGroup().
2022-01-02Improve the documentation of KConfigPrivate::allSubGroups()Igor Kushnir
2022-01-02KConfigPrivate::copyGroup: remove redundant entryMap lookupIgor Kushnir
2022-01-02groupList: convert each group name from UTF-8 onceIgor Kushnir
Usually multiple key entries belong to each group. Before this commit every key entry's group name was converted from UTF-8 to UTF-16 and then inserted into a set. With this commit every key entry's group name is inserted as a std::string_view into a set, and only unique group names are converted to UTF-16 in the end. This should improve performance.
2022-01-02Exclude deleted groups from groupList()Igor Kushnir
This commit is an alternative to the earlier incorrect and reverted b3dc879e8b108c26c929bfbe551bcdf77f140e94. That commit contained several mistakes and an algorithmic complexity increase: 1) the added conditions were inverted: should have been `hasNonDeletedEntries` (without `!`); 2) KConfigPrivate::groupList() passed group instead of key.mGroup to hasNonDeletedEntries(); 3) The complexity of hasNonDeletedEntries() is O(entryMap.size()). Calls to this function were added into loops that iterated entryMap.size() times. So the overall complexity of groupList() increased from linear to quadratic. This fix collects `mGroup`s of non-deleted key entries instead of `mGroup`s of group entries. The number of key entries can be much greater than the number of group entries, so this fix hurts performance. But at least the algorithmic complexity of groupList() stays linear. Future commits can optimize the loops and make them almost as fast or even faster than before this fix. The `!key.mKey.isNull() && !entryMapIt->bDeleted` checks added in this commit are consistent with the check in KConfigPrivate::hasNonDeletedEntries(). KConfig::hasGroupImpl() forwards its argument to hasNonDeletedEntries() with the following comment: // No need to look for the actual group entry anymore, or for subgroups: // a group exists if it contains any non-deleted entry. BUG: 384039 FIXED-IN: 5.90
2022-01-02groupList: don't copy unnecessarily; add constIgor Kushnir
2021-10-11Create utility method for moving entries from one group to anotherAlexander Lohnau
This will become especially useful when moving state data from the config file to a dedicated state data file. Task: https://phabricator.kde.org/T12549
2021-08-28GIT_SILENT: we can use std::as_const directlyLaurent Montel
2021-08-18Port to QStrinViewAhmad Samir
Now that KF requires Qt 5.15.2; this basically reverts commit 2e8742e64fc0 with some trivial changes. NO_CHANGELOG
2021-08-13clang-tidy: one declaration per line; braces around statementsAhmad Samir
clang-tidy checks: readability-isolate-declaration and readability-braces-around-statements KF task: https://phabricator.kde.org/T14729 GIT_SILENT
2021-08-03KConfig: sort keys in keyListImpl() so unittests can rely on itDavid Faure
The code was using a QSet (hash-based), use a std::set instead for unicity, it gives us sorting for free. We probably want to do the same in groupList(), but that's separate.
2021-07-04Cache global config filesAleix Pol
Whenever we read a config file, we are first parsing kdeglobalsrc. This caches the parsed entries so that they can be reused as long as it hasn't changed. This reduces the parseConfig calls (which is mostly prominent at early process startup) from 18 to 12 (33%) ksmserver-logout-greeter. This also means there's better cache locality as well as less memory allocated as a lot of objects are shared but I have not measured this.
2021-05-25Revert "fix deleted group is in listGroups"Nate Graham
This reverts commit b3dc879e8b108c26c929bfbe551bcdf77f140e94. This change breaks plasmashell startup and possible other apps as well. Reverting so the root cause can be investigated without time pressure.
2021-05-25fix deleted group is in listGroupsLieven Hey
calling deleteGroup only deletes all entries but the group does still exists in listGroups this is somewhat irritating since calling exists on that group will return false with this patch the group does no longer exists in listGroup
2021-05-09Revert QStringView portAhmad Samir
QStringView has some bits of API that were only added in 5.15.2, whereas KF requires 5.15.0. This reverts commit 1780fb2a237af80ddc1f9cfb70cb892b53b91990.
2021-05-02Minor code refactoringAhmad Samir
Some methods in ConfigLoaderHandler always returned true, change them to return void instead. Also port them to take a QStringView instead of QStringRef, this doesn't require a lot of changes because a QStringView can be constructed from a QStringRef. QXmlStreamAttribute methods like value() and name() return QStringRef in Qt5 and QStringView in Qt6, "fix" the issue by using auto keyword, which works in both cases. QStringView::toInt() isn't efficient in Qt5 so make the build conditional. NO_CHANGELOG
2021-03-06Minor code optimisationAhmad Samir
- Use more range-for loops where appropriate - Use auto instead of the usually-long iterator type names - Use cbegin/cend(), to match the std:: containers, less confusion - Use qDeleteAll instead of a for loop - Make a QRE with a long-ish pattern static NO_CHANGELOG
2021-02-24Add KEntryMap::constFindEntry() methodAhmad Samir
- This has the same logic as QMap::constFind(); less detaching and now we can use auto keyword when creating iterators and always get a const_iterator even when calling constFindEntry() on a non-const map. - Use QCOMPARE() where appropriate in the unit tests.
2021-02-22Fix formatting in a couple of places after running clang-formatAhmad Samir
NO_CHANGELOG
2021-02-22Run clang-format on all cpp/h filesAhmad Samir
NO_CHANGELOG
2021-02-06Preincerment/predecrement operator where the post ones aren't neededAhmad Samir
NO_CHANGELOG
2021-02-06General code cleanupAhmad Samir
Fix some clazy warnings, and some other minor code optimisations. NO_CHANGELOG
2020-12-18Remove ifdefs, we require Qt 5.14 nowAlbert Astals Cid
2020-12-03Fix commentAhmad Samir
GIT_SILENT
2020-11-07Fix KConfigGroup::copyTo with KConfigBase::NotifyFabian Vogt
Without this, bNotify was not set on copies, making Notify a noop. CCBUG: 428771
2020-10-23If include is define in .h remove it if it's defined in .cpp too (scripted)Laurent Montel
2020-08-24Fix qt warning:Laurent Montel
"QtPrivate::DeprecatedRefClassBehavior::warn|?libKF5ConfigCore.so.5?|?libKF5ConfigCore.so.5? Using QCharRef with an index pointing outside the valid range of a QString. The corresponding behavior is deprecated, and will be changed in a future version of Qt." We try to access to an invalid index.
2020-07-25Update sGlobalFileName when QStandardPaths TestMode is toggledAhmad Samir
When running unit tests, usually QStandardPaths TestMode is enabled so as not to mess up the config files in the home dir of the dev running the unit tests; sGlobalFileName, a global static, was defined only once, which meant that if KSharedConfig::openConfig() is called before the unit test has had a chance to call QStandardPaths::setTestModeEnabled(true), then sGlobalFileName will go on referring to the wrong kdeglobals file (as can be seen in dfaure's debugging of the issue at [1]). Change the code so as to detect QStandardPaths TestMode status and change sGlobalFileName as needed. All unit tests still pass. [1] https://invent.kde.org/frameworks/kio/-/merge_requests/77#note_74124
2020-07-07Use camelcase include. (scripted)Laurent Montel
2020-03-30QAtomicInteger::loadRelaxed/storeRelaxed() are available since Qt 5.14Ahmad Samir
A similar patch was approved in https://phabricator.kde.org/D26102
2020-03-22KConfig: Convert to SPDX license statementsAndreas Cord-Landwehr
Summary: Convert license headers to SPDX statements and add license files as required by REUSE specification. Reviewers: cgiboudeaux Reviewed By: cgiboudeaux Subscribers: ognarb, cgiboudeaux, kde-frameworks-devel Tags: #frameworks Maniphest Tasks: T11550 Differential Revision: https://phabricator.kde.org/D27601
2019-12-19Port deprecated methodsLaurent Montel
2019-12-04Don't use nullptr as flag. Make it compile against qt5.15Laurent Montel
2019-10-31These methods were adding in qt5.15Laurent Montel
2019-10-30Make it compile against qt5.15 without deprecated methodLaurent Montel
2019-10-18Use ECMGenerateExportHeader to manage deprecated API betterFriedrich W. H. Kossebau
Summary: Allows * projects linking to KConfigCore/Gui to hide deprecated API up to a given version or silence deprecation warnings after a given version, using * -DKCONFIGCORE_DISABLE_DEPRECATED_BEFORE_AND_AT * -DKCONFIGCORE_NO_DEPRECATED * -DKCONFIGCORE_DEPRECATED_WARNINGS_SINCE * -DKCONFIGCORE_NO_DEPRECATED_WARNINGS * -DKCONFIGGUI_DISABLE_DEPRECATED_BEFORE_AND_AT * -DKCONFIGGUI_NO_DEPRECATED * -DKCONFIGGUI_DEPRECATED_WARNINGS_SINCE * -DKCONFIGGUI_NO_DEPRECATED_WARNINGS or * -DKF_DISABLE_DEPRECATED_BEFORE_AND_AT * -DKF_NO_DEPRECATED * -DKF_DEPRECATED_WARNINGS_SINCE * -DKF_NO_DEPRECATED_WARNINGS * to build KConfigCore/Gui optionally with deprecated API excluded from the build, using "EXCLUDE_DEPRECATED_BEFORE_AND_AT" cmake argument. Test Plan: Builds with EXCLUDE_DEPRECATED_BEFORE_AND_AT set to 0, 4.0.0, 5.0.0, 5.11.0, 5.24.0, 5.39.0, 5.42.0, CURRENT. Reviewers: #frameworks, mlaurent Reviewed By: mlaurent Subscribers: mlaurent, kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D24496
2019-08-25Use more initializer listsFriedrich W. H. Kossebau
GIT_SILENT
2019-08-24String code optimization: use QLatin1String/QChar overload for string concatFriedrich W. H. Kossebau
GIT_SILENT
2019-08-24String code optimization: use QLatin1String overload for == & !=Friedrich W. H. Kossebau
GIT_SILENT
2019-08-14Add a logging category for logs warningsMéven Car
Summary: Disable logs unless the logging category kf5.kconfig.core is enabled Test Plan: ctest Reviewers: #frameworks, apol, cgiboudeaux Reviewed By: cgiboudeaux Subscribers: cgiboudeaux, mikeroyal, apol, kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D22061
2019-08-07Security: remove support for $(...) in config keys with [$e] marker.David Faure
Summary: It is very unclear at this point what a valid use case for this feature would possibly be. The old documentation only mentions $(hostname) as an example, which can be done with $HOSTNAME instead. Note that $(...) is still supported in Exec lines of desktop files, this does not require [$e] anyway (and actually works better without it, otherwise the $ signs need to be doubled to obey kconfig $e escaping rules...). Test Plan: ctest passes; various testcases with $(...) in desktop files, directory files, and config files, no longer execute commands. Reviewers: mdawson, aacid, broulik, davidedmundson, kossebau, apol, sitter, security-team Reviewed By: mdawson, davidedmundson Subscribers: ZaWertun, rikmills, fvogt, ngraham, kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D22979
2019-04-01Add Notify capability to revertToDefaultKai Uwe Broulik
This enables KConfigWatcher to detect those changes, too. Differential Revision: https://phabricator.kde.org/D20039
2019-03-03[Kconfig] Compile without foreachLaurent Montel
Summary: compile without foreach Test Plan: Unittest Ok as previously Reviewers: dfaure Reviewed By: dfaure Subscribers: kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D19326
2019-02-04KConfig: handle directory symlinks correctly.David Faure
Summary: When /home is a symlink, for instance (as is often the case on FreeBSD), group deletion would fail because KConfig was comparing non-canonical paths with canonical-paths: QDEBUG : KConfigTest::testDelete() Comparing "/home/adridg/.qttest/config/ kconfigtest_subdir/kconfigtest" and "/usr/home/adridg/.qttest/config/ kconfigtest_subdir/kconfigtest" Test Plan: mkdir /tmp/derp; ln -s /tmp/derp /tmp/drop HOME=/tmp/derp bin/kconfigtest testDelete # Success HOME=/tmp/drop bin/kconfigtest testDelete # Fail Reviewers: adridg, arichardson, apol Reviewed By: apol Subscribers: kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D14927
2018-10-15Fix logic error in NotifyFlag testingDavid Edmundson
Notify was changed to 0x08 | Persistent as it implied the other flag state. However this change was not updated in the test. Reviewed-by: Kai Uwe Broulik
2018-10-10Add mechanism to notify other clients of config changes over DBusDavid Edmundson
Summary: Intention is not to create a registry like system, but to replace KDElibs4Support::KGlobalSettings and to replace other system settingss -> some app communication in a more generic way. writeEntry gains an additional flag Notify which if set, will notify clients of what has actually changed when we sync. Rationale to put this into KConfig was so that we could have everything batched and sychronised to the file sync and to get the fine detailed exposure of what has actually changed which we don't get with a file watcher. Default behaviour remains identical without any broadcast messages. As it is a new dependency it is purely optional and anything referencing DBus is not in the public API. Our deployment on platforms without DBus tend to be standalone applications anyway. Test Plan: Attached unit test Reviewers: broulik, dfaure Reviewed By: broulik, dfaure Subscribers: dfaure, broulik, zzag, kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D13034
2018-10-10Expose getter method for KConfig::addConfigSourcesDavid Edmundson
Test Plan: Used in subsequent patch Subscribers: kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D13033
2018-08-14Remove warning about old kiosk feature that no longer applies.David Faure
Summary: The concept of KStandardDirs resources no longer exists; and anyway kiosk users disable things at the feature level, not at the config file level. Test Plan: Compiles without warnings Reviewers: davidedmundson, arichardson, broulik Reviewed By: broulik Subscribers: kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D14829
2018-03-11Remove not necessary QtCore and coLaurent Montel