From 83306bb01f5e9e3f4ccd610b78f5c22e813b45cf Mon Sep 17 00:00:00 2001
From: John Preston <johnprestonmail@gmail.com>
Date: Thu, 18 Apr 2019 13:04:14 +0400
Subject: [PATCH] Replace QList with std::deque in notifications.

---
 Telegram/SourceFiles/history/history.cpp | 31 ++++++++++++------------
 Telegram/SourceFiles/history/history.h   |  5 ++--
 2 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp
index 34ca2ff12..fff5485a7 100644
--- a/Telegram/SourceFiles/history/history.cpp
+++ b/Telegram/SourceFiles/history/history.cpp
@@ -94,32 +94,31 @@ int History::height() const {
 }
 
 void History::removeNotification(not_null<HistoryItem*> item) {
-	if (!notifies.isEmpty()) {
-		for (auto i = notifies.begin(), e = notifies.end(); i != e; ++i) {
-			if ((*i) == item) {
-				notifies.erase(i);
-				break;
-			}
-		}
-	}
+	_notifications.erase(
+		ranges::remove(_notifications, item),
+		end(_notifications));
 }
 
 HistoryItem *History::currentNotification() {
-	return notifies.isEmpty() ? 0 : notifies.front();
+	return empty(_notifications)
+		? nullptr
+		: _notifications.front().get();
 }
 
 bool History::hasNotification() const {
-	return !notifies.isEmpty();
+	return !empty(_notifications);
 }
 
 void History::skipNotification() {
-	if (!notifies.isEmpty()) {
-		notifies.pop_front();
+	if (!empty(_notifications)) {
+		_notifications.pop_front();
 	}
 }
 
 void History::popNotification(HistoryItem *item) {
-	if (!notifies.isEmpty() && notifies.back() == item) notifies.pop_back();
+	if (!empty(_notifications) && (_notifications.back() == item)) {
+		_notifications.pop_back();
+	}
 }
 
 bool History::hasPendingResizedItems() const {
@@ -1236,7 +1235,7 @@ void History::newItemAdded(not_null<HistoryItem*> item) {
 		}
 	} else if (item->unread()) {
 		if (!isChannel() || peer->asChannel()->amIn()) {
-			notifies.push_back(item);
+			_notifications.push_back(item);
 			App::main()->newUnreadMsg(this, item);
 		}
 	} else {
@@ -2114,7 +2113,7 @@ void History::finishBuildingFrontBlock() {
 }
 
 void History::clearNotifications() {
-	notifies.clear();
+	_notifications.clear();
 }
 
 bool History::loadedAtBottom() const {
@@ -3001,7 +3000,7 @@ void History::clear(ClearType type) {
 		lastKeyboardInited = false;
 		_loadedAtTop = _loadedAtBottom = false;
 	} else {
-		notifies.clear();
+		_notifications.clear();
 		owner().notifyHistoryCleared(this);
 		changeUnreadCount(-unreadCount());
 		if (type == ClearType::DeleteChat) {
diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h
index 353f1a0bf..b95f01a66 100644
--- a/Telegram/SourceFiles/history/history.h
+++ b/Telegram/SourceFiles/history/history.h
@@ -335,9 +335,6 @@ public:
 
 	not_null<PeerData*> peer;
 
-	typedef QList<HistoryItem*> NotifyQueue;
-	NotifyQueue notifies;
-
 	// we save the last showAtMsgId to restore the state when switching
 	// between different conversation histories
 	MsgId showAtMsgId = ShowAtUnreadMsgId;
@@ -515,6 +512,8 @@ private:
 	Ui::SendActionAnimation _sendActionAnimation;
 	base::flat_map<SendAction::Type, crl::time> _mySendActions;
 
+	std::deque<not_null<HistoryItem*>> _notifications;
+
 	std::weak_ptr<AdminLog::LocalIdManager> _adminLogIdManager;
 
  };