diff --git a/Telegram/SourceFiles/api/api_updates.cpp b/Telegram/SourceFiles/api/api_updates.cpp index d3e80896c..7cb1347d5 100644 --- a/Telegram/SourceFiles/api/api_updates.cpp +++ b/Telegram/SourceFiles/api/api_updates.cpp @@ -1510,7 +1510,7 @@ void Updates::feedUpdate(const MTPUpdate &update) { return; } auto possiblyReadMentions = base::flat_set(); - for_const (auto &msgId, d.vmessages().v) { + for (const auto &msgId : d.vmessages().v) { if (auto item = session().data().message(channel, msgId.v)) { if (item->isUnreadMedia() || item->isUnreadMention()) { item->markMediaRead(); diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index ce0cbfcfb..828ca3b6d 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -500,74 +500,98 @@ void ApiWrap::sendMessageFail( } } -void ApiWrap::requestMessageData(ChannelData *channel, MsgId msgId, RequestMessageDataCallback callback) { - auto &req = (channel ? _channelMessageDataRequests[channel][msgId] : _messageDataRequests[msgId]); +void ApiWrap::requestMessageData( + ChannelData *channel, + MsgId msgId, + RequestMessageDataCallback callback) { + auto &requests = channel + ? _channelMessageDataRequests[channel][msgId] + : _messageDataRequests[msgId]; if (callback) { - req.callbacks.append(callback); + requests.callbacks.push_back(callback); + } + if (!requests.requestId) { + _messageDataResolveDelayed.call(); } - if (!req.requestId) _messageDataResolveDelayed.call(); } -QVector ApiWrap::collectMessageIds(const MessageDataRequests &requests) { +QVector ApiWrap::collectMessageIds( + const MessageDataRequests &requests) { auto result = QVector(); result.reserve(requests.size()); - for (auto i = requests.cbegin(), e = requests.cend(); i != e; ++i) { - if (i.value().requestId > 0) continue; - result.push_back(MTP_inputMessageID(MTP_int(i.key()))); + for (const auto &[msgId, request] : requests) { + if (request.requestId > 0) { + continue; + } + result.push_back(MTP_inputMessageID(MTP_int(msgId))); } return result; } -ApiWrap::MessageDataRequests *ApiWrap::messageDataRequests(ChannelData *channel, bool onlyExisting) { +auto ApiWrap::messageDataRequests(ChannelData *channel, bool onlyExisting) +-> MessageDataRequests* { if (channel) { auto i = _channelMessageDataRequests.find(channel); - if (i == _channelMessageDataRequests.cend()) { + if (i == end(_channelMessageDataRequests)) { if (onlyExisting) { return nullptr; } - i = _channelMessageDataRequests.insert(channel, MessageDataRequests()); + i = _channelMessageDataRequests.emplace( + channel, + MessageDataRequests()).first; } - return &i.value(); + return &i->second; } return &_messageDataRequests; } void ApiWrap::resolveMessageDatas() { - if (_messageDataRequests.isEmpty() && _channelMessageDataRequests.isEmpty()) return; + if (_messageDataRequests.empty() && _channelMessageDataRequests.empty()) { + return; + } - auto ids = collectMessageIds(_messageDataRequests); + const auto ids = collectMessageIds(_messageDataRequests); if (!ids.isEmpty()) { - auto requestId = request(MTPmessages_GetMessages( + const auto requestId = request(MTPmessages_GetMessages( MTP_vector(ids) - )).done([this](const MTPmessages_Messages &result, mtpRequestId requestId) { + )).done([=]( + const MTPmessages_Messages &result, + mtpRequestId requestId) { gotMessageDatas(nullptr, result, requestId); - }).fail([this](const MTP::Error &error, mtpRequestId requestId) { + }).fail([=](const MTP::Error &error, mtpRequestId requestId) { finalizeMessageDataRequest(nullptr, requestId); }).afterDelay(kSmallDelayMs).send(); - for (auto &request : _messageDataRequests) { - if (request.requestId > 0) continue; + + for (auto &[msgId, request] : _messageDataRequests) { + if (request.requestId > 0) { + continue; + } request.requestId = requestId; } } for (auto j = _channelMessageDataRequests.begin(); j != _channelMessageDataRequests.cend();) { - if (j->isEmpty()) { + if (j->second.empty()) { j = _channelMessageDataRequests.erase(j); continue; } - auto ids = collectMessageIds(j.value()); + const auto ids = collectMessageIds(j->second); if (!ids.isEmpty()) { - auto channel = j.key(); - auto requestId = request(MTPchannels_GetMessages( - j.key()->inputChannel, + const auto channel = j->first; + const auto requestId = request(MTPchannels_GetMessages( + channel->inputChannel, MTP_vector(ids) - )).done([=](const MTPmessages_Messages &result, mtpRequestId requestId) { + )).done([=]( + const MTPmessages_Messages &result, + mtpRequestId requestId) { gotMessageDatas(channel, result, requestId); }).fail([=](const MTP::Error &error, mtpRequestId requestId) { finalizeMessageDataRequest(channel, requestId); }).afterDelay(kSmallDelayMs).send(); - for (auto &request : *j) { - if (request.requestId > 0) continue; + for (auto &[msgId, request] : j->second) { + if (request.requestId > 0) { + continue; + } request.requestId = requestId; } } @@ -612,16 +636,16 @@ void ApiWrap::finalizeMessageDataRequest( auto requests = messageDataRequests(channel, true); if (requests) { for (auto i = requests->begin(); i != requests->cend();) { - if (i.value().requestId == requestId) { - for_const (auto &callback, i.value().callbacks) { - callback(channel, i.key()); + if (i->second.requestId == requestId) { + for (const auto &callback : i->second.callbacks) { + callback(channel, i->first); } i = requests->erase(i); } else { ++i; } } - if (channel && requests->isEmpty()) { + if (channel && requests->empty()) { _channelMessageDataRequests.remove(channel); } } diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index 9b7257ff2..ba1cdb848 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -416,11 +416,12 @@ public: private: struct MessageDataRequest { - using Callbacks = QList; + using Callbacks = std::vector; + mtpRequestId requestId = 0; Callbacks callbacks; }; - using MessageDataRequests = QMap; + using MessageDataRequests = base::flat_map; using SharedMediaType = Storage::SharedMediaType; struct StickersByEmoji { @@ -460,8 +461,11 @@ private: ChannelData *channel, mtpRequestId requestId); - QVector collectMessageIds(const MessageDataRequests &requests); - MessageDataRequests *messageDataRequests(ChannelData *channel, bool onlyExisting = false); + [[nodiscard]] QVector collectMessageIds( + const MessageDataRequests &requests); + [[nodiscard]] MessageDataRequests *messageDataRequests( + ChannelData *channel, + bool onlyExisting = false); void gotChatFull( not_null peer, @@ -580,7 +584,9 @@ private: base::flat_map _modifyRequests; MessageDataRequests _messageDataRequests; - QMap _channelMessageDataRequests; + base::flat_map< + ChannelData*, + MessageDataRequests> _channelMessageDataRequests; SingleQueuedInvokation _messageDataResolveDelayed; using PeerRequests = QMap; diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index eb7ad3ab9..ab5c3c35a 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -1452,7 +1452,7 @@ void RevokePublicLinkBox::Inner::mouseReleaseEvent(QMouseEvent *e) { void RevokePublicLinkBox::Inner::paintEvent(QPaintEvent *e) { Painter p(this); p.translate(0, _rowsTop); - for_const (auto &row, _rows) { + for (const auto &row : _rows) { paintChat(p, row, (row.peer == _selected)); p.translate(0, _rowHeight); } diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index 6bfa8ace4..198f41df6 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -470,7 +470,7 @@ void StickersBox::getArchivedDone( auto addedSet = false; auto changedSets = false; - for_const (const auto &stickerSet, stickers.vsets().v) { + for (const auto &stickerSet : stickers.vsets().v) { const MTPDstickerSet *setData = nullptr; switch (stickerSet.type()) { case mtpc_stickerSetCovered: { @@ -2291,7 +2291,7 @@ int StickersBox::Inner::getRowIndex(uint64 setId) const { } void StickersBox::Inner::setFullOrder(const StickersSetsOrder &order) { - for_const (auto setId, order) { + for (const auto setId : order) { auto index = getRowIndex(setId); if (index >= 0) { auto row = std::move(_rows[index]); diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index 6f0cbfaed..720fe59d9 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -379,9 +379,12 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) { bool listAllSuggestions = _filter.isEmpty(); if (_addInlineBots) { - for_const (auto user, cRecentInlineBots()) { - if (user->isInaccessible()) continue; - if (!listAllSuggestions && filterNotPassedByUsername(user)) continue; + for (const auto user : cRecentInlineBots()) { + if (user->isInaccessible() + || (!listAllSuggestions + && filterNotPassedByUsername(user))) { + continue; + } mrows.push_back({ user }); ++recentInlineBots; } diff --git a/Telegram/SourceFiles/core/utils.h b/Telegram/SourceFiles/core/utils.h index 2d73b601f..8a9aec63a 100644 --- a/Telegram/SourceFiles/core/utils.h +++ b/Telegram/SourceFiles/core/utils.h @@ -32,12 +32,6 @@ inline bool in_range(Value &&value, From &&from, Till &&till) { } // namespace base -// using for_const instead of plain range-based for loop to ensure usage of const_iterator -// it is important for the copy-on-write Qt containers -// if you have "QVector v" then "for (T * const p : v)" will still call QVector::detach(), -// while "for_const (T *p, v)" won't and "for_const (T *&p, v)" won't compile -#define for_const(range_declaration, range_expression) for (range_declaration : std::as_const(range_expression)) - static const int32 ScrollMax = INT_MAX; extern uint64 _SharedMemoryLocation[]; diff --git a/Telegram/SourceFiles/data/data_drafts.h b/Telegram/SourceFiles/data/data_drafts.h index a8c391d5b..3b7b17a3b 100644 --- a/Telegram/SourceFiles/data/data_drafts.h +++ b/Telegram/SourceFiles/data/data_drafts.h @@ -126,7 +126,7 @@ private: using HistoryDrafts = base::flat_map>; inline bool draftStringIsEmpty(const QString &text) { - for_const (auto ch, text) { + for (const auto ch : text) { if (!ch.isSpace()) { return false; } diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp index 91b6a8ee1..f13746003 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp @@ -182,10 +182,12 @@ private: not_null _channel; QPointer _allFlags; - QMap> _filterFlags; + base::flat_map< + MTPDchannelAdminLogEventsFilter::Flags, + QPointer> _filterFlags; QPointer _allUsers; - QMap, QPointer> _admins; + base::flat_map, QPointer> _admins; bool _restoringInvariant = false; struct Row { @@ -224,7 +226,7 @@ void FilterBox::Inner::createAllActionsCheckbox(const FilterValue &filter) { ) | rpl::start_with_next([=](bool checked) { if (!std::exchange(_restoringInvariant, true)) { auto allChecked = _allFlags->checked(); - for_const (auto &&checkbox, _filterFlags) { + for (const auto &[flag, checkbox] : _filterFlags) { checkbox->setChecked(allChecked); } _restoringInvariant = false; @@ -241,12 +243,12 @@ void FilterBox::Inner::createActionsCheckboxes(const FilterValue &filter) { auto addFlag = [this, &filter](Flags flag, QString &&text) { auto checked = (filter.flags == 0) || (filter.flags & flag); auto checkbox = addRow(object_ptr(this, std::move(text), checked, st::defaultBoxCheckbox), st::adminLogFilterLittleSkip); - _filterFlags.insert(flag, checkbox); + _filterFlags[flag] = checkbox; checkbox->checkedChanges( ) | rpl::start_with_next([=](bool checked) { if (!std::exchange(_restoringInvariant, true)) { auto allChecked = true; - for_const (auto &&checkbox, _filterFlags) { + for (const auto &[flag, checkbox] : _filterFlags) { if (!checkbox->checked()) { allChecked = false; break; @@ -285,7 +287,7 @@ void FilterBox::Inner::createAllUsersCheckbox(const FilterValue &filter) { ) | rpl::start_with_next([=](bool checked) { if (!std::exchange(_restoringInvariant, true)) { auto allChecked = _allUsers->checked(); - for_const (auto &&checkbox, _admins) { + for (const auto &[user, checkbox] : _admins) { checkbox->setChecked(allChecked); } _restoringInvariant = false; @@ -297,14 +299,16 @@ void FilterBox::Inner::createAllUsersCheckbox(const FilterValue &filter) { } void FilterBox::Inner::createAdminsCheckboxes(const std::vector> &admins, const FilterValue &filter) { - for (auto user : admins) { - auto checked = filter.allUsers || base::contains(filter.admins, user); - auto checkbox = addRow(object_ptr(this, user, checked), st::adminLogFilterLittleSkip); + for (const auto user : admins) { + const auto checked = filter.allUsers || base::contains(filter.admins, user); + const auto checkbox = addRow( + object_ptr(this, user, checked), + st::adminLogFilterLittleSkip); checkbox->checkedChanges( ) | rpl::start_with_next([=](bool checked) { if (!std::exchange(_restoringInvariant, true)) { auto allChecked = true; - for_const (auto &&checkbox, _admins) { + for (const auto &[user, checkbox] : _admins) { if (!checkbox->checked()) { allChecked = false; break; @@ -319,13 +323,13 @@ void FilterBox::Inner::createAdminsCheckboxes(const std::vectorlifetime()); - _admins.insert(user, checkbox); + _admins[user] = checkbox; } } bool FilterBox::Inner::canSave() const { - for (auto i = _filterFlags.cbegin(), e = _filterFlags.cend(); i != e; ++i) { - if (i.value()->checked()) { + for (const auto &[flag, checkbox] : _filterFlags) { + if (checkbox->checked()) { return true; } } @@ -335,9 +339,9 @@ bool FilterBox::Inner::canSave() const { FilterValue FilterBox::Inner::filter() const { auto result = FilterValue(); auto allChecked = true; - for (auto i = _filterFlags.cbegin(), e = _filterFlags.cend(); i != e; ++i) { - if (i.value()->checked()) { - result.flags |= i.key(); + for (const auto &[flag, checkbox] : _filterFlags) { + if (checkbox->checked()) { + result.flags |= flag; } else { allChecked = false; } @@ -348,9 +352,9 @@ FilterValue FilterBox::Inner::filter() const { result.allUsers = _allUsers->checked(); if (!result.allUsers) { result.admins.reserve(_admins.size()); - for (auto i = _admins.cbegin(), e = _admins.cend(); i != e; ++i) { - if (i.value()->checked()) { - result.admins.push_back(i.key()); + for (const auto &[user, checkbox] : _admins) { + if (checkbox->checked()) { + result.admins.push_back(user); } } } diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index 1a7b19496..4eebda25e 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -549,7 +549,7 @@ void ReplyKeyboard::resize(int width, int height) { int widthForText = widthForButtons; int widthOfText = 0; int maxMinButtonWidth = 0; - for_const (auto &button, row) { + for (const auto &button : row) { widthOfText += qMax(button.text.maxWidth(), 1); int minButtonWidth = _st->minButtonWidth(button.type); widthForText -= minButtonWidth; @@ -559,7 +559,7 @@ void ReplyKeyboard::resize(int width, int height) { bool enough = (widthForButtons - s * maxMinButtonWidth) >= widthOfText; float64 x = 0; - for (Button &button : row) { + for (auto &button : row) { int buttonw = qMax(button.text.maxWidth(), 1); float64 textw = buttonw, minw = _st->minButtonWidth(button.type); float64 w = textw; @@ -587,10 +587,10 @@ void ReplyKeyboard::resize(int width, int height) { } bool ReplyKeyboard::isEnoughSpace(int width, const style::BotKeyboardButton &st) const { - for_const (auto &row, _rows) { + for (const auto &row : _rows) { int s = row.size(); int widthLeft = width - ((s - 1) * st.margin + s * 2 * st.padding); - for_const (auto &button, row) { + for (const auto &button : row) { widthLeft -= qMax(button.text.maxWidth(), 1); if (widthLeft < 0) { if (row.size() > 3) { @@ -662,8 +662,8 @@ void ReplyKeyboard::paint( ClickHandlerPtr ReplyKeyboard::getLink(QPoint point) const { Assert(_width > 0); - for_const (auto &row, _rows) { - for_const (auto &button, row) { + for (const auto &row : _rows) { + for (const auto &button : row) { QRect rect(button.rect); // just ignore the buttons that didn't layout well diff --git a/Telegram/SourceFiles/history/history_service.cpp b/Telegram/SourceFiles/history/history_service.cpp index f74aa0b24..b7e911ed9 100644 --- a/Telegram/SourceFiles/history/history_service.cpp +++ b/Telegram/SourceFiles/history/history_service.cpp @@ -951,7 +951,7 @@ void HistoryService::setServiceText(const PreparedText &prepared) { prepared.text, Ui::ItemTextServiceOptions()); auto linkIndex = 0; - for_const (auto &link, prepared.links) { + for (const auto &link : prepared.links) { // Link indices start with 1. _text.setLink(++linkIndex, link); } diff --git a/Telegram/SourceFiles/profile/profile_block_group_members.cpp b/Telegram/SourceFiles/profile/profile_block_group_members.cpp index 4b38c9514..90257866d 100644 --- a/Telegram/SourceFiles/profile/profile_block_group_members.cpp +++ b/Telegram/SourceFiles/profile/profile_block_group_members.cpp @@ -233,7 +233,7 @@ void GroupMembersWidget::sortMembers() { void GroupMembersWidget::updateOnlineCount() { bool onlyMe = true; int newOnlineCount = 0; - for_const (auto item, items()) { + for (const auto item : items()) { auto member = getMember(item); auto user = member->user(); auto isOnline = !user->isBot() && Data::OnlineTextActive(member->onlineTill, _now); @@ -433,7 +433,7 @@ void GroupMembersWidget::updateOnlineDisplay() { _now = base::unixtime::now(); bool changed = false; - for_const (auto item, items()) { + for (const auto item : items()) { if (!item->statusHasOnlineColor) { if (!item->peer->isSelf()) { continue; diff --git a/Telegram/SourceFiles/profile/profile_block_peer_list.cpp b/Telegram/SourceFiles/profile/profile_block_peer_list.cpp index 7ab81b1bc..4f5918398 100644 --- a/Telegram/SourceFiles/profile/profile_block_peer_list.cpp +++ b/Telegram/SourceFiles/profile/profile_block_peer_list.cpp @@ -63,8 +63,9 @@ void PeerListWidget::paintContents(Painter &p) { auto left = getListLeft(); auto top = getListTop(); - auto from = floorclamp(_visibleTop - top, _st.height, 0, _items.size()); - auto to = ceilclamp(_visibleBottom - top, _st.height, 0, _items.size()); + const auto count = int(_items.size()); + auto from = floorclamp(_visibleTop - top, _st.height, 0, count); + auto to = ceilclamp(_visibleBottom - top, _st.height, 0, count); for (auto i = from; i < to; ++i) { auto y = top + i * _st.height; auto selected = (_pressed >= 0) ? (i == _pressed) : (i == _selected); @@ -147,7 +148,7 @@ void PeerListWidget::mousePressEvent(QMouseEvent *e) { _pressed = _selected; _pressedRemove = _selectedRemove; if (_pressed >= 0 && !_pressedRemove) { - auto item = _items[_pressed]; + const auto item = _items[_pressed]; if (!item->ripple) { auto memberRowWidth = rowWidth(); auto mask = Ui::RippleAnimation::rectMask(QSize(memberRowWidth, _st.height)); @@ -170,7 +171,7 @@ void PeerListWidget::mousePressReleased(Qt::MouseButton button) { auto pressed = std::exchange(_pressed, -1); auto pressedRemove = base::take(_pressedRemove); if (pressed >= 0 && pressed < _items.size()) { - if (auto &ripple = _items[pressed]->ripple) { + if (const auto &ripple = _items[pressed]->ripple) { ripple->lastStop(); } if (pressed == _selected && pressedRemove == _selectedRemove && button == Qt::LeftButton) { @@ -274,7 +275,7 @@ void PeerListWidget::preloadPhotos() { } void PeerListWidget::refreshVisibility() { - setVisible(!_items.isEmpty()); + setVisible(!_items.empty()); } } // namespace Profile diff --git a/Telegram/SourceFiles/profile/profile_block_peer_list.h b/Telegram/SourceFiles/profile/profile_block_peer_list.h index 69231da3b..002db0233 100644 --- a/Telegram/SourceFiles/profile/profile_block_peer_list.h +++ b/Telegram/SourceFiles/profile/profile_block_peer_list.h @@ -52,7 +52,7 @@ public: int getListLeft() const; - const QList &items() const { + const std::vector &items() const { return _items; } int itemsCount() const { @@ -129,7 +129,7 @@ private: Fn _removedCallback; Fn _updateItemCallback; - QList _items; + std::vector _items; int _visibleTop = 0; int _visibleBottom = 0; diff --git a/Telegram/SourceFiles/settings/settings_notifications.cpp b/Telegram/SourceFiles/settings/settings_notifications.cpp index 1cdc3f095..17c00d445 100644 --- a/Telegram/SourceFiles/settings/settings_notifications.cpp +++ b/Telegram/SourceFiles/settings/settings_notifications.cpp @@ -98,7 +98,7 @@ private: int _oldCount; - QVector _cornerSamples[4]; + std::vector _cornerSamples[4]; }; @@ -350,7 +350,8 @@ void NotificationsCount::setOverCorner(ScreenCorner corner) { if (corner == _overCorner) { return; } - for_const (auto widget, _cornerSamples[static_cast(_overCorner)]) { + const auto index = static_cast(_overCorner); + for (const auto widget : _cornerSamples[index]) { widget->hideFast(); } } else { @@ -362,7 +363,7 @@ void NotificationsCount::setOverCorner(ScreenCorner corner) { _overCorner = corner; auto &samples = _cornerSamples[static_cast(_overCorner)]; - auto samplesAlready = samples.size(); + auto samplesAlready = int(samples.size()); auto samplesNeeded = _oldCount; auto samplesLeave = qMin(samplesAlready, samplesNeeded); for (int i = 0; i != samplesLeave; ++i) { @@ -394,8 +395,8 @@ void NotificationsCount::clearOverCorner() { Core::App().notifications().notifySettingsChanged( ChangeType::DemoIsHidden); - for_const (const auto &samples, _cornerSamples) { - for_const (const auto widget, samples) { + for (const auto &samples : _cornerSamples) { + for (const auto widget : samples) { widget->hideFast(); } } @@ -426,8 +427,8 @@ void NotificationsCount::mouseReleaseEvent(QMouseEvent *e) { } NotificationsCount::~NotificationsCount() { - for_const (auto &samples, _cornerSamples) { - for_const (auto widget, samples) { + for (const auto &samples : _cornerSamples) { + for (const auto widget : samples) { widget->detach(); } } diff --git a/Telegram/SourceFiles/storage/storage_account.cpp b/Telegram/SourceFiles/storage/storage_account.cpp index 659321e19..8d1e5010a 100644 --- a/Telegram/SourceFiles/storage/storage_account.cpp +++ b/Telegram/SourceFiles/storage/storage_account.cpp @@ -2258,7 +2258,7 @@ void Account::readInstalledMasks() { } void Account::writeSavedGifs() { - auto &saved = _owner->session().data().stickers().savedGifs(); + const auto &saved = _owner->session().data().stickers().savedGifs(); if (saved.isEmpty()) { if (_savedGifsKey) { ClearKey(_savedGifsKey, _basePath); @@ -2267,7 +2267,7 @@ void Account::writeSavedGifs() { } } else { quint32 size = sizeof(quint32); // count - for_const (auto gif, saved) { + for (const auto gif : saved) { size += Serialize::Document::sizeInStream(gif); } @@ -2277,7 +2277,7 @@ void Account::writeSavedGifs() { } EncryptedDescriptor data(size); data.stream << quint32(saved.size()); - for_const (auto gif, saved) { + for (const auto gif : saved) { Serialize::Document::writeToStream(data.stream, gif); } FileWriteDescriptor file(_savedGifsKey, _basePath); diff --git a/Telegram/SourceFiles/ui/widgets/multi_select.cpp b/Telegram/SourceFiles/ui/widgets/multi_select.cpp index cd95b9e20..fc4d0dd77 100644 --- a/Telegram/SourceFiles/ui/widgets/multi_select.cpp +++ b/Telegram/SourceFiles/ui/widgets/multi_select.cpp @@ -188,7 +188,7 @@ QRect MultiSelect::Item::paintArea(int outerWidth) const { return rect(); } auto yMin = 0, yMax = 0; - for_const (auto ©, _copies) { + for (const auto © : _copies) { accumulate_max(yMax, copy.y); if (yMin) { accumulate_min(yMin, copy.y); @@ -671,7 +671,7 @@ void MultiSelect::Inner::computeItemsGeometry(int newWidth) { auto itemTop = 0; auto widthLeft = newWidth; auto maxVisiblePadding = qMax(_st.padding.left(), _st.padding.right()); - for_const (auto &item, _items) { + for (const auto &item : _items) { auto itemWidth = item->getWidth(); Assert(itemWidth <= newWidth); if (itemWidth > widthLeft) { @@ -721,7 +721,7 @@ void MultiSelect::Inner::finishHeightAnimation() { } void MultiSelect::Inner::setItemText(uint64 itemId, const QString &text) { - for_const (auto &item, _items) { + for (const auto &item : _items) { if (item->id() == itemId) { item->setText(text); updateItemsGeometry(); @@ -783,7 +783,7 @@ int MultiSelect::Inner::getItemsCount() const { QVector MultiSelect::Inner::getItems() const { auto result = QVector(); result.reserve(_items.size()); - for_const (auto &item, _items) { + for (const auto &item : _items) { result.push_back(item->id()); } return result; diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index 02bd82d75..9a058d3a7 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -98,7 +98,7 @@ QPixmap Manager::hiddenUserpicPlaceholder() const { } bool Manager::hasReplyingNotification() const { - for_const (auto ¬ification, _notifications) { + for (const auto ¬ification : _notifications) { if (notification->isReplying()) { return true; } @@ -110,7 +110,7 @@ void Manager::settingsChanged(ChangeType change) { if (change == ChangeType::Corner) { auto startPosition = notificationStartPosition(); auto shiftDirection = notificationShiftDirection(); - for_const (auto ¬ification, _notifications) { + for (const auto ¬ification : _notifications) { notification->updatePosition(startPosition, shiftDirection); } if (_hideAll) { @@ -142,7 +142,7 @@ void Manager::settingsChanged(ChangeType change) { } void Manager::demoMasterOpacityCallback() { - for_const (auto ¬ification, _notifications) { + for (const auto ¬ification : _notifications) { notification->updateOpacity(); } if (_hideAll) { @@ -173,7 +173,7 @@ void Manager::checkLastInput() { void Manager::startAllHiding() { if (!hasReplyingNotification()) { int notHidingCount = 0; - for_const (auto ¬ification, _notifications) { + for (const auto ¬ification : _notifications) { if (notification->isShowing()) { ++notHidingCount; } else { @@ -188,7 +188,7 @@ void Manager::startAllHiding() { } void Manager::stopAllHiding() { - for_const (auto ¬ification, _notifications) { + for (const auto ¬ification : _notifications) { notification->stopHiding(); } if (_hideAll) { @@ -400,7 +400,7 @@ void Manager::doClearFromItem(not_null item) { }), _queuedNotifications.cend()); auto showNext = false; - for_const (auto ¬ification, _notifications) { + for (const auto ¬ification : _notifications) { if (notification->unlinkItem(item)) { showNext = true; } @@ -424,7 +424,7 @@ bool Manager::doSkipFlashBounce() const { } void Manager::doUpdateAll() { - for_const (auto ¬ification, _notifications) { + for (const auto ¬ification : _notifications) { notification->updateNotifyDisplay(); } } diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor_block.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor_block.cpp index 9212e21e6..ec23105fe 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor_block.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor_block.cpp @@ -55,11 +55,11 @@ public: fillSearchIndex(); } - const OrderedSet &searchWords() const { + const base::flat_set &searchWords() const { return _searchWords; } bool searchWordsContain(const QString &needle) const { - for_const (auto &word, _searchWords) { + for (const auto &word : _searchWords) { if (word.startsWith(needle)) { return true; } @@ -67,7 +67,7 @@ public: return false; } - const OrderedSet &searchStartChars() const { + const base::flat_set &searchStartChars() const { return _searchStartChars; } @@ -106,8 +106,8 @@ private: QString _valueString; Ui::Text::String _description = { st::windowMinWidth / 2 }; - OrderedSet _searchWords; - OrderedSet _searchStartChars; + base::flat_set _searchWords; + base::flat_set _searchStartChars; int _top = 0; int _height = 0; @@ -154,11 +154,16 @@ void EditorBlock::Row::fillValueString() { void EditorBlock::Row::fillSearchIndex() { _searchWords.clear(); _searchStartChars.clear(); - auto toIndex = _name + ' ' + _copyOf + ' ' + TextUtilities::RemoveAccents(_description.toString()) + ' ' + _valueString; - auto words = toIndex.toLower().split(SearchSplitter, base::QStringSkipEmptyParts); - for_const (auto &word, words) { - _searchWords.insert(word); - _searchStartChars.insert(word[0]); + const auto toIndex = _name + + ' ' + _copyOf + + ' ' + TextUtilities::RemoveAccents(_description.toString()) + + ' ' + _valueString; + const auto words = toIndex.toLower().split( + SearchSplitter, + base::QStringSkipEmptyParts); + for (const auto &word : words) { + _searchWords.emplace(word); + _searchStartChars.emplace(word[0]); } } @@ -252,7 +257,7 @@ void EditorBlock::addToSearch(const Row &row) { if (!query.isEmpty()) resetSearch(); auto index = findRowIndex(&row); - for_const (auto ch, row.searchStartChars()) { + for (const auto ch : row.searchStartChars()) { _searchIndex[ch].insert(index); } @@ -264,12 +269,12 @@ void EditorBlock::removeFromSearch(const Row &row) { if (!query.isEmpty()) resetSearch(); auto index = findRowIndex(&row); - for_const (auto ch, row.searchStartChars()) { - auto it = _searchIndex.find(ch); - if (it != _searchIndex.cend()) { - it->remove(index); - if (it->isEmpty()) { - _searchIndex.erase(it); + for (const auto ch : row.searchStartChars()) { + const auto i = _searchIndex.find(ch); + if (i != end(_searchIndex)) { + i->second.remove(index); + if (i->second.empty()) { + _searchIndex.erase(i); } } } @@ -339,7 +344,9 @@ void EditorBlock::scrollToSelected() { } void EditorBlock::searchByQuery(QString query) { - auto words = TextUtilities::PrepareSearchWords(query, &SearchSplitter); + const auto words = TextUtilities::PrepareSearchWords( + query, + &SearchSplitter); query = words.isEmpty() ? QString() : words.join(' '); if (_searchQuery != query) { setSelected(-1); @@ -348,28 +355,28 @@ void EditorBlock::searchByQuery(QString query) { _searchQuery = query; _searchResults.clear(); - auto toFilter = OrderedSet(); - for_const (auto &word, words) { + auto toFilter = (base::flat_set*)nullptr; + for (const auto &word : words) { if (word.isEmpty()) continue; - auto testToFilter = _searchIndex.value(word[0]); - if (testToFilter.isEmpty()) { - toFilter.clear(); + const auto i = _searchIndex.find(word[0]); + if (i == end(_searchIndex) || i->second.empty()) { + toFilter = nullptr; break; - } else if (toFilter.isEmpty() || testToFilter.size() < toFilter.size()) { - toFilter = testToFilter; + } else if (!toFilter || i->second.size() < toFilter->size()) { + toFilter = &i->second; } } - if (!toFilter.isEmpty()) { - auto allWordsFound = [&words](const Row &row) { - for_const (auto &word, words) { + if (toFilter) { + const auto allWordsFound = [&](const Row &row) { + for (const auto &word : words) { if (!row.searchWordsContain(word)) { return false; } } return true; }; - for_const (auto index, toFilter) { + for (const auto index : *toFilter) { if (allWordsFound(_data[index])) { _searchResults.push_back(index); } @@ -423,7 +430,7 @@ void EditorBlock::sortByDistance(const QColor &to) { template void EditorBlock::enumerateRows(Callback callback) { if (isSearch()) { - for_const (auto index, _searchResults) { + for (const auto index : _searchResults) { if (!callback(_data[index])) { break; } @@ -440,7 +447,7 @@ void EditorBlock::enumerateRows(Callback callback) { template void EditorBlock::enumerateRows(Callback callback) const { if (isSearch()) { - for_const (auto index, _searchResults) { + for (const auto index : _searchResults) { if (!callback(_data[index])) { break; } diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor_block.h b/Telegram/SourceFiles/window/themes/window_theme_editor_block.h index 05d93593e..8352e41b0 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor_block.h +++ b/Telegram/SourceFiles/window/themes/window_theme_editor_block.h @@ -144,8 +144,8 @@ private: QMap _indices; QString _searchQuery; - QVector _searchResults; - QMap> _searchIndex; + std::vector _searchResults; + base::flat_map> _searchIndex; int _selected = -1; int _pressed = -1;