mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Clear memory while scrolling in topics / discussions.
This commit is contained in:
parent
f410a3b6da
commit
3b1d13eac9
2 changed files with 28 additions and 9 deletions
|
@ -490,6 +490,8 @@ void ListWidget::setGeometryCrashAnnotations(not_null<Element*> view) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ListWidget::refreshRows(const Data::MessagesSlice &old) {
|
void ListWidget::refreshRows(const Data::MessagesSlice &old) {
|
||||||
|
Expects(_viewsCapacity.empty());
|
||||||
|
|
||||||
saveScrollState();
|
saveScrollState();
|
||||||
|
|
||||||
const auto addedToEndFrom = (old.skippedAfter == 0
|
const auto addedToEndFrom = (old.skippedAfter == 0
|
||||||
|
@ -507,13 +509,14 @@ void ListWidget::refreshRows(const Data::MessagesSlice &old) {
|
||||||
_resizePending = true;
|
_resizePending = true;
|
||||||
_items.clear();
|
_items.clear();
|
||||||
_items.reserve(_slice.ids.size());
|
_items.reserve(_slice.ids.size());
|
||||||
|
std::swap(_views, _viewsCapacity);
|
||||||
auto nearestIndex = -1;
|
auto nearestIndex = -1;
|
||||||
for (const auto &fullId : _slice.ids) {
|
for (const auto &fullId : _slice.ids) {
|
||||||
if (const auto item = session().data().message(fullId)) {
|
if (const auto item = session().data().message(fullId)) {
|
||||||
if (_slice.nearestToAround == fullId) {
|
if (_slice.nearestToAround == fullId) {
|
||||||
nearestIndex = int(_items.size());
|
nearestIndex = int(_items.size());
|
||||||
}
|
}
|
||||||
const auto view = enforceViewForItem(item);
|
const auto view = enforceViewForItem(item, _viewsCapacity);
|
||||||
_items.push_back(view);
|
_items.push_back(view);
|
||||||
if (destroyingBarElement == view) {
|
if (destroyingBarElement == view) {
|
||||||
destroyingBarElement = nullptr;
|
destroyingBarElement = nullptr;
|
||||||
|
@ -541,6 +544,13 @@ void ListWidget::refreshRows(const Data::MessagesSlice &old) {
|
||||||
_bar = {};
|
_bar = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const auto &[item, view] : _viewsCapacity) {
|
||||||
|
if (const auto raw = view.get()) {
|
||||||
|
viewReplaced(raw, nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_viewsCapacity.clear();
|
||||||
|
|
||||||
checkUnreadBarCreation();
|
checkUnreadBarCreation();
|
||||||
restoreScrollState();
|
restoreScrollState();
|
||||||
if (!_itemsRevealHeight) {
|
if (!_itemsRevealHeight) {
|
||||||
|
@ -868,9 +878,16 @@ Element *ListWidget::viewForItem(const HistoryItem *item) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
not_null<Element*> ListWidget::enforceViewForItem(
|
not_null<Element*> ListWidget::enforceViewForItem(
|
||||||
not_null<HistoryItem*> item) {
|
not_null<HistoryItem*> item,
|
||||||
if (const auto view = viewForItem(item)) {
|
ViewsMap &old) {
|
||||||
return view;
|
if (const auto i = old.find(item); i != end(old)) {
|
||||||
|
if (i->second) {
|
||||||
|
return _views.emplace(
|
||||||
|
item,
|
||||||
|
base::take(i->second)).first->second.get();
|
||||||
|
} else if (const auto j = _views.find(item); j != end(_views)) {
|
||||||
|
return j->second.get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const auto [i, ok] = _views.emplace(
|
const auto [i, ok] = _views.emplace(
|
||||||
item,
|
item,
|
||||||
|
|
|
@ -359,6 +359,9 @@ private:
|
||||||
using PointState = HistoryView::PointState;
|
using PointState = HistoryView::PointState;
|
||||||
using CursorState = HistoryView::CursorState;
|
using CursorState = HistoryView::CursorState;
|
||||||
using ChosenReaction = HistoryView::Reactions::ChosenReaction;
|
using ChosenReaction = HistoryView::Reactions::ChosenReaction;
|
||||||
|
using ViewsMap = base::flat_map<
|
||||||
|
not_null<HistoryItem*>,
|
||||||
|
std::unique_ptr<Element>>;
|
||||||
|
|
||||||
struct MouseState {
|
struct MouseState {
|
||||||
MouseState();
|
MouseState();
|
||||||
|
@ -433,7 +436,9 @@ private:
|
||||||
|
|
||||||
Element *viewForItem(FullMsgId itemId) const;
|
Element *viewForItem(FullMsgId itemId) const;
|
||||||
Element *viewForItem(const HistoryItem *item) const;
|
Element *viewForItem(const HistoryItem *item) const;
|
||||||
not_null<Element*> enforceViewForItem(not_null<HistoryItem*> item);
|
not_null<Element*> enforceViewForItem(
|
||||||
|
not_null<HistoryItem*> item,
|
||||||
|
ViewsMap &old);
|
||||||
|
|
||||||
void mouseActionStart(
|
void mouseActionStart(
|
||||||
const QPoint &globalPosition,
|
const QPoint &globalPosition,
|
||||||
|
@ -623,10 +628,7 @@ private:
|
||||||
int _idsLimit = kMinimalIdsLimit;
|
int _idsLimit = kMinimalIdsLimit;
|
||||||
Data::MessagesSlice _slice;
|
Data::MessagesSlice _slice;
|
||||||
std::vector<not_null<Element*>> _items;
|
std::vector<not_null<Element*>> _items;
|
||||||
std::map<
|
ViewsMap _views, _viewsCapacity;
|
||||||
not_null<HistoryItem*>,
|
|
||||||
std::unique_ptr<Element>,
|
|
||||||
std::less<>> _views;
|
|
||||||
int _itemsTop = 0;
|
int _itemsTop = 0;
|
||||||
int _itemsWidth = 0;
|
int _itemsWidth = 0;
|
||||||
int _itemsHeight = 0;
|
int _itemsHeight = 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue