aboutsummaryrefslogtreecommitdiff
path: root/src/core/kconfigdata_p.h
diff options
context:
space:
mode:
authorIgor Kushnir <igorkuo@gmail.com>2021-12-25 09:46:44 +0200
committerIgor Kushnir <igorkuo@gmail.com>2022-01-02 20:20:55 +0200
commitacccefbc667e7ee2c481b2fd0b45ba2f12e9237a (patch)
treefed24ecb20cf41a7de6ad0d8beb93b9028483f49 /src/core/kconfigdata_p.h
parent117835244a23ccc906ee0b0d462d67c38480b914 (diff)
downloadkconfig-acccefbc667e7ee2c481b2fd0b45ba2f12e9237a.tar.gz
kconfig-acccefbc667e7ee2c481b2fd0b45ba2f12e9237a.tar.bz2
Look for entries with common group prefix in entryMap's subrange
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().
Diffstat (limited to 'src/core/kconfigdata_p.h')
-rw-r--r--src/core/kconfigdata_p.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/core/kconfigdata_p.h b/src/core/kconfigdata_p.h
index 5e5246f3..beb18f45 100644
--- a/src/core/kconfigdata_p.h
+++ b/src/core/kconfigdata_p.h
@@ -155,6 +155,17 @@ inline bool operator<(const KEntryKey &k1, const KEntryKey &k2)
return (!k1.bDefault && k2.bDefault);
}
+/**
+ * Returns the minimum key that has @a mGroup == @p group.
+ *
+ * @note The returned "minimum key" is consistent with KEntryKey's operator<().
+ * The return value of this function can be passed to KEntryMap::lowerBound().
+ */
+inline KEntryKey minimumGroupKey(const QByteArray &group)
+{
+ return KEntryKey(group, QByteArray{}, true, false);
+}
+
QDebug operator<<(QDebug dbg, const KEntryKey &key);
QDebug operator<<(QDebug dbg, const KEntry &entry);
@@ -230,6 +241,25 @@ public:
}
bool revertEntry(const QByteArray &group, const QByteArray &key, EntryOptions options, SearchFlags flags = SearchFlags());
+
+ template<typename ConstIteratorUser>
+ void forEachEntryWhoseGroupStartsWith(const QByteArray &groupPrefix, ConstIteratorUser callback) const
+ {
+ for (auto it = lowerBound(minimumGroupKey(groupPrefix)), end = cend(); it != end && it.key().mGroup.startsWith(groupPrefix); ++it) {
+ callback(it);
+ }
+ }
+
+ template<typename ConstIteratorPredicate>
+ bool anyEntryWhoseGroupStartsWith(const QByteArray &groupPrefix, ConstIteratorPredicate predicate) const
+ {
+ for (auto it = lowerBound(minimumGroupKey(groupPrefix)), end = cend(); it != end && it.key().mGroup.startsWith(groupPrefix); ++it) {
+ if (predicate(it)) {
+ return true;
+ }
+ }
+ return false;
+ }
};
Q_DECLARE_OPERATORS_FOR_FLAGS(KEntryMap::SearchFlags)
Q_DECLARE_OPERATORS_FOR_FLAGS(KEntryMap::EntryOptions)