[pim/libkleo/release/26.08] src/kleo: Use simple linear search to find given key filter
Ingo Klöcker <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 0d92587c1a6b921557e7b611f6cd139083825e10 by Ingo Klöcker, on behalf of Ingo Klöcker.
Committed on 29/07/2026 at 11:52.
Pushed by kloecker into branch 'release/26.08'.
Use simple linear search to find given key filter
The complicated two-stage search doesn't work anymore because the filters
are no longer sorted by decreasing specificity. Only the subset of filters
loaded from libkleopatrarc (which are used for styling the keys) are still
sorted by specificity.
The two-stage search was anyway over-engineered because there are only
about 20 key filters so that linear search is fast enough.
GnuPG-bug-id: 8323
(cherry picked from commit 1917c33cbac656cab6443ef8c952bcbf63f6e9a7)
M +2 -10 src/kleo/keyfiltermanager.cpp
https://invent.kde.org/pim/libkleo/-/commit/0d92587c1a6b921557e7b611f6cd139083825e10
diff --git a/src/kleo/keyfiltermanager.cpp b/src/kleo/keyfiltermanager.cpp
index 14affcd7..3091cbf7 100644
--- a/src/kleo/keyfiltermanager.cpp
+++ b/src/kleo/keyfiltermanager.cpp
@@ -326,13 +326,6 @@ std::vector<std::shared_ptr<KeyFilter>> KeyFilterManager::filtersMatching(const
return result;
}
-namespace
-{
-static const auto byDecreasingSpecificity = [](const std::shared_ptr<KeyFilter> &lhs, const std::shared_ptr<KeyFilter> &rhs) {
- return lhs->specificity() > rhs->specificity();
-};
-}
-
static inline QDebug operator<<(QDebug debug, const KConfigGroup &configGroup)
{
return debug << configGroup.name();
@@ -434,9 +427,8 @@ QModelIndex KeyFilterManager::toModelIndex(const std::shared_ptr<KeyFilter> &kf)
if (!kf) {
return {};
}
- const auto pair = std::equal_range(d->filters.cbegin(), d->filters.cend(), kf, byDecreasingSpecificity);
- const auto it = std::find(pair.first, pair.second, kf);
- if (it != pair.second) {
+ const auto it = std::ranges::find(d->filters, kf);
+ if (it != d->filters.end()) {
return d->model.index(it - d->filters.begin());
} else {
return QModelIndex();