cache channel view id

This commit is contained in:
unknown 2024-10-23 01:29:37 +02:00
parent 0e4897969b
commit 1bdb118391
4 changed files with 41 additions and 29 deletions

View file

@ -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<QUuid> &ids)
{
this->channelFilters_ = std::make_shared<FilterSet>(ids);
this->updateID();
}
QList<QUuid> 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

View file

@ -215,6 +215,9 @@ public:
Scrollbar *scrollbar();
using ChannelViewID = std::size_t;
ChannelViewID getID() const;
pajlada::Signals::Signal<QMouseEvent *> mouseDown;
pajlada::Signals::NoArgSignal selectionChanged;
pajlada::Signals::Signal<HighlightState, const MessagePtr &>
@ -318,6 +321,9 @@ private:
void showReplyThreadPopup(const MessagePtr &message);
bool canReplyToMessages() const;
void updateID();
ChannelViewID id_{};
bool layoutQueued_ = false;
bool bufferInvalidationQueued_ = false;

View file

@ -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)
{

View file

@ -126,23 +126,8 @@ private:
const MessagePtr &message) const;
struct HighlightSources {
using ChannelViewId = std::size_t;
static ChannelViewId GetChannelViewId(
const QString &channelName, const QList<QUuid> &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<ChannelViewId> newMessageSource;
std::unordered_set<ChannelViewId> highlightedSource;
std::unordered_set<ChannelView::ChannelViewID> newMessageSource;
std::unordered_set<ChannelView::ChannelViewID> 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_;