[plasma/union] src: Include style in ElementQuery result cache

Arjen Hiemstra <[email protected]> Wed, 5 Aug 2026 11:15:06 +0000 (UTC)
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 58d1b7e265c6b1c1060a57c37589bb02a2fdd3b0 by Arjen Hiemstra.
Committed on 05/08/2026 at 11:09.
Pushed by ahiemstra into branch 'master'.

Include style in ElementQuery result cache

Otherwise we may end up matching cache results for one style with
another style, which will mess things up.

M  +3    -2    src/Element.h
M  +1    -1    src/ElementQuery.cpp

https://invent.kde.org/plasma/union/-/commit/58d1b7e265c6b1c1060a57c37589bb02a2fdd3b0

diff --git a/src/Element.h b/src/Element.h
index 62308683..800508ef 100644
--- a/src/Element.h
+++ b/src/Element.h
@@ -281,10 +281,11 @@ using ElementList = QList<Element::Ptr>;
  *
  * Get a cache key for an ElementList.
  */
-inline std::size_t elementListCacheKey(const Union::ElementList &key, std::size_t seed = 0)
+inline std::size_t elementListCacheKey(const Union::ElementList &key, std::size_t seed = 0, const QList<std::size_t> &extra = {})
 {
     QList<std::size_t> elements;
-    elements.reserve(key.size());
+    elements.reserve(key.size() + extra.size());
+    elements.append(extra);
     std::ranges::transform(key, std::back_inserter(elements), [seed](const Union::Element::Ptr &element) {
         return element->cacheKey(seed);
     });
diff --git a/src/ElementQuery.cpp b/src/ElementQuery.cpp
index 819bc0ff..1a872efd 100644
--- a/src/ElementQuery.cpp
+++ b/src/ElementQuery.cpp
@@ -43,7 +43,7 @@ bool ElementQuery::execute()
 {
     qCInfo(UNION_QUERY) << "Trying to match" << d->elements;
 
-    auto cacheKey = elementListCacheKey(d->elements, QHashSeed::globalSeed());
+    auto cacheKey = elementListCacheKey(d->elements, QHashSeed::globalSeed(), {qHash(d->style.get())});
     if (auto cached = ElementQueryPrivate::s_matchesCache.value(cacheKey); cached) {
         qCInfo(UNION_QUERY) << "Matched from cache";
         d->properties = cached.value();