From 1bdb11839129fe3ceff801746b653dc77f4d4622 Mon Sep 17 00:00:00 2001 From: unknown <1310440+hemirt@users.noreply.github.com> Date: Wed, 23 Oct 2024 01:29:37 +0200 Subject: [PATCH] cache channel view id --- src/widgets/helper/ChannelView.cpp | 27 +++++++++++++++++++++++++++ src/widgets/helper/ChannelView.hpp | 6 ++++++ src/widgets/helper/NotebookTab.cpp | 14 ++++---------- src/widgets/helper/NotebookTab.hpp | 23 ++++------------------- 4 files changed, 41 insertions(+), 29 deletions(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 54d5dded5..7e2f37409 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1063,6 +1063,8 @@ void ChannelView::setChannel(const ChannelPtr &underlyingChannel) this->underlyingChannel_ = underlyingChannel; + this->updateID(); + this->performLayout(); this->queueUpdate(); @@ -1081,6 +1083,8 @@ void ChannelView::setChannel(const ChannelPtr &underlyingChannel) void ChannelView::setFilters(const QList &ids) { this->channelFilters_ = std::make_shared(ids); + + this->updateID(); } QList ChannelView::getFilterIds() const @@ -3237,4 +3241,27 @@ void ChannelView::pendingLinkInfoStateChanged() this->tooltipWidget_->applyLastBoundsCheck(); } +void ChannelView::updateID() +{ + if (!this->underlyingChannel_) + { + // cannot update + return; + } + + std::size_t seed = 0; + auto first = qHash(this->underlyingChannel_->getName()); + auto second = qHash(this->getFilterIds()); + + boost::hash_combine(seed, first); + boost::hash_combine(seed, second); + + this->id_ = seed; +} + +ChannelView::ChannelViewID ChannelView::getID() const +{ + return this->id_; +} + } // namespace chatterino diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index 52d08803a..74fd0aa39 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -215,6 +215,9 @@ public: Scrollbar *scrollbar(); + using ChannelViewID = std::size_t; + ChannelViewID getID() const; + pajlada::Signals::Signal mouseDown; pajlada::Signals::NoArgSignal selectionChanged; pajlada::Signals::Signal @@ -318,6 +321,9 @@ private: void showReplyThreadPopup(const MessagePtr &message); bool canReplyToMessages() const; + void updateID(); + ChannelViewID id_{}; + bool layoutQueued_ = false; bool bufferInvalidationQueued_ = false; diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index eddb44123..23d7d90bc 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -306,13 +306,13 @@ bool NotebookTab::isSelected() const } void NotebookTab::removeNewMessageSource( - const HighlightSources::ChannelViewId &source) + const ChannelView::ChannelViewID &source) { this->highlightSources_.newMessageSource.erase(source); } void NotebookTab::removeHighlightedSource( - const HighlightSources::ChannelViewId &source) + const ChannelView::ChannelViewID &source) { this->highlightSources_.highlightedSource.erase(source); } @@ -333,10 +333,7 @@ void NotebookTab::removeHighlightStateChangeSources( void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource) { - const auto &channelName = channelViewSource.underlyingChannel()->getName(); - const auto &channelFilterIds = channelViewSource.getFilterIds(); - auto channelViewId = - HighlightSources::GetChannelViewId(channelName, channelFilterIds); + auto channelViewId = channelViewSource.getID(); this->removeHighlightedSource(channelViewId); this->removeNewMessageSource(channelViewId); this->updateHighlightStateDueSourcesChange(); @@ -556,10 +553,7 @@ void NotebookTab::updateHighlightState(HighlightState newHighlightStyle, // message is highlighting unvisible tab - const auto &channelName = channelViewSource.underlyingChannel()->getName(); - const auto &channelFilterIds = channelViewSource.getFilterIds(); - auto channelViewId = - HighlightSources::GetChannelViewId(channelName, channelFilterIds); + auto channelViewId = channelViewSource.getID(); switch (newHighlightStyle) { diff --git a/src/widgets/helper/NotebookTab.hpp b/src/widgets/helper/NotebookTab.hpp index 5bef5fbee..2d3865daa 100644 --- a/src/widgets/helper/NotebookTab.hpp +++ b/src/widgets/helper/NotebookTab.hpp @@ -126,23 +126,8 @@ private: const MessagePtr &message) const; struct HighlightSources { - using ChannelViewId = std::size_t; - - static ChannelViewId GetChannelViewId( - const QString &channelName, const QList &channelFilterIds) - { - std::size_t seed = 0; - auto first = qHash(channelName); - auto second = qHash(channelFilterIds); - - boost::hash_combine(seed, first); - boost::hash_combine(seed, second); - - return seed; - } - - std::unordered_set newMessageSource; - std::unordered_set highlightedSource; + std::unordered_set newMessageSource; + std::unordered_set highlightedSource; void clear() { @@ -152,8 +137,8 @@ private: } highlightSources_; void removeHighlightStateChangeSources(const HighlightSources &toRemove); - void removeNewMessageSource(const HighlightSources::ChannelViewId &source); - void removeHighlightedSource(const HighlightSources::ChannelViewId &source); + void removeNewMessageSource(const ChannelView::ChannelViewID &source); + void removeHighlightedSource(const ChannelView::ChannelViewID &source); void updateHighlightStateDueSourcesChange(); QPropertyAnimation positionChangedAnimation_;