From 0448e707fce798d6864320ef629ae681845bde26 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 7 Apr 2026 14:09:06 +0100 Subject: desktop/popup: cache tree count --- src/desktop/view/Popup.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/desktop/view/Popup.cpp') diff --git a/src/desktop/view/Popup.cpp b/src/desktop/view/Popup.cpp index cf0c981b..7791e921 100644 --- a/src/desktop/view/Popup.cpp +++ b/src/desktop/view/Popup.cpp @@ -418,7 +418,8 @@ void CPopup::invalidateTreeExtentsCache() { if (!head) return; - head->m_treeExtentsCacheDirty = true; + head->m_treeExtentsCacheDirty = true; + head->m_treePopupCountCacheDirty = true; } void CPopup::recheckTree() { @@ -561,6 +562,37 @@ const CBox& CPopup::popupTreeExtents() const { return head->m_cachedTreeExtents; } +int CPopup::popupTreeCount() const { + auto head = popupHead(); + if (!head) + return 0; + + if (!head->m_treePopupCountCacheDirty) + return head->m_cachedTreePopupCount; + + head->m_treePopupCountCacheDirty = false; + head->m_cachedTreePopupCount = 0; + + std::vector> popups; + popups.emplace_back(head); + + for (size_t i = 0; i < popups.size(); ++i) { + const auto& popup = popups[i]; + if (!popup) + continue; + + for (const auto& c : popup->m_children) { + if (!c) + continue; + + popups.emplace_back(c); + head->m_cachedTreePopupCount++; + } + } + + return head->m_cachedTreePopupCount; +} + SP CPopup::at(const Vector2D& globalCoords, bool allowsInput) { thread_local std::vector> popups; popups.clear(); -- cgit v1.2.3