Remove for_const macro.

This commit is contained in:
John Preston 2021-09-03 14:09:57 +03:00
parent 2a2607d026
commit 23e9e7b9f0
20 changed files with 179 additions and 139 deletions

View file

@ -1510,7 +1510,7 @@ void Updates::feedUpdate(const MTPUpdate &update) {
return; return;
} }
auto possiblyReadMentions = base::flat_set<MsgId>(); auto possiblyReadMentions = base::flat_set<MsgId>();
for_const (auto &msgId, d.vmessages().v) { for (const auto &msgId : d.vmessages().v) {
if (auto item = session().data().message(channel, msgId.v)) { if (auto item = session().data().message(channel, msgId.v)) {
if (item->isUnreadMedia() || item->isUnreadMention()) { if (item->isUnreadMedia() || item->isUnreadMention()) {
item->markMediaRead(); item->markMediaRead();

View file

@ -500,74 +500,98 @@ void ApiWrap::sendMessageFail(
} }
} }
void ApiWrap::requestMessageData(ChannelData *channel, MsgId msgId, RequestMessageDataCallback callback) { void ApiWrap::requestMessageData(
auto &req = (channel ? _channelMessageDataRequests[channel][msgId] : _messageDataRequests[msgId]); ChannelData *channel,
MsgId msgId,
RequestMessageDataCallback callback) {
auto &requests = channel
? _channelMessageDataRequests[channel][msgId]
: _messageDataRequests[msgId];
if (callback) { if (callback) {
req.callbacks.append(callback); requests.callbacks.push_back(callback);
}
if (!requests.requestId) {
_messageDataResolveDelayed.call();
} }
if (!req.requestId) _messageDataResolveDelayed.call();
} }
QVector<MTPInputMessage> ApiWrap::collectMessageIds(const MessageDataRequests &requests) { QVector<MTPInputMessage> ApiWrap::collectMessageIds(
const MessageDataRequests &requests) {
auto result = QVector<MTPInputMessage>(); auto result = QVector<MTPInputMessage>();
result.reserve(requests.size()); result.reserve(requests.size());
for (auto i = requests.cbegin(), e = requests.cend(); i != e; ++i) { for (const auto &[msgId, request] : requests) {
if (i.value().requestId > 0) continue; if (request.requestId > 0) {
result.push_back(MTP_inputMessageID(MTP_int(i.key()))); continue;
}
result.push_back(MTP_inputMessageID(MTP_int(msgId)));
} }
return result; return result;
} }
ApiWrap::MessageDataRequests *ApiWrap::messageDataRequests(ChannelData *channel, bool onlyExisting) { auto ApiWrap::messageDataRequests(ChannelData *channel, bool onlyExisting)
-> MessageDataRequests* {
if (channel) { if (channel) {
auto i = _channelMessageDataRequests.find(channel); auto i = _channelMessageDataRequests.find(channel);
if (i == _channelMessageDataRequests.cend()) { if (i == end(_channelMessageDataRequests)) {
if (onlyExisting) { if (onlyExisting) {
return nullptr; return nullptr;
} }
i = _channelMessageDataRequests.insert(channel, MessageDataRequests()); i = _channelMessageDataRequests.emplace(
channel,
MessageDataRequests()).first;
} }
return &i.value(); return &i->second;
} }
return &_messageDataRequests; return &_messageDataRequests;
} }
void ApiWrap::resolveMessageDatas() { 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()) { if (!ids.isEmpty()) {
auto requestId = request(MTPmessages_GetMessages( const auto requestId = request(MTPmessages_GetMessages(
MTP_vector<MTPInputMessage>(ids) MTP_vector<MTPInputMessage>(ids)
)).done([this](const MTPmessages_Messages &result, mtpRequestId requestId) { )).done([=](
const MTPmessages_Messages &result,
mtpRequestId requestId) {
gotMessageDatas(nullptr, result, requestId); gotMessageDatas(nullptr, result, requestId);
}).fail([this](const MTP::Error &error, mtpRequestId requestId) { }).fail([=](const MTP::Error &error, mtpRequestId requestId) {
finalizeMessageDataRequest(nullptr, requestId); finalizeMessageDataRequest(nullptr, requestId);
}).afterDelay(kSmallDelayMs).send(); }).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; request.requestId = requestId;
} }
} }
for (auto j = _channelMessageDataRequests.begin(); j != _channelMessageDataRequests.cend();) { for (auto j = _channelMessageDataRequests.begin(); j != _channelMessageDataRequests.cend();) {
if (j->isEmpty()) { if (j->second.empty()) {
j = _channelMessageDataRequests.erase(j); j = _channelMessageDataRequests.erase(j);
continue; continue;
} }
auto ids = collectMessageIds(j.value()); const auto ids = collectMessageIds(j->second);
if (!ids.isEmpty()) { if (!ids.isEmpty()) {
auto channel = j.key(); const auto channel = j->first;
auto requestId = request(MTPchannels_GetMessages( const auto requestId = request(MTPchannels_GetMessages(
j.key()->inputChannel, channel->inputChannel,
MTP_vector<MTPInputMessage>(ids) MTP_vector<MTPInputMessage>(ids)
)).done([=](const MTPmessages_Messages &result, mtpRequestId requestId) { )).done([=](
const MTPmessages_Messages &result,
mtpRequestId requestId) {
gotMessageDatas(channel, result, requestId); gotMessageDatas(channel, result, requestId);
}).fail([=](const MTP::Error &error, mtpRequestId requestId) { }).fail([=](const MTP::Error &error, mtpRequestId requestId) {
finalizeMessageDataRequest(channel, requestId); finalizeMessageDataRequest(channel, requestId);
}).afterDelay(kSmallDelayMs).send(); }).afterDelay(kSmallDelayMs).send();
for (auto &request : *j) { for (auto &[msgId, request] : j->second) {
if (request.requestId > 0) continue; if (request.requestId > 0) {
continue;
}
request.requestId = requestId; request.requestId = requestId;
} }
} }
@ -612,16 +636,16 @@ void ApiWrap::finalizeMessageDataRequest(
auto requests = messageDataRequests(channel, true); auto requests = messageDataRequests(channel, true);
if (requests) { if (requests) {
for (auto i = requests->begin(); i != requests->cend();) { for (auto i = requests->begin(); i != requests->cend();) {
if (i.value().requestId == requestId) { if (i->second.requestId == requestId) {
for_const (auto &callback, i.value().callbacks) { for (const auto &callback : i->second.callbacks) {
callback(channel, i.key()); callback(channel, i->first);
} }
i = requests->erase(i); i = requests->erase(i);
} else { } else {
++i; ++i;
} }
} }
if (channel && requests->isEmpty()) { if (channel && requests->empty()) {
_channelMessageDataRequests.remove(channel); _channelMessageDataRequests.remove(channel);
} }
} }

View file

@ -416,11 +416,12 @@ public:
private: private:
struct MessageDataRequest { struct MessageDataRequest {
using Callbacks = QList<RequestMessageDataCallback>; using Callbacks = std::vector<RequestMessageDataCallback>;
mtpRequestId requestId = 0; mtpRequestId requestId = 0;
Callbacks callbacks; Callbacks callbacks;
}; };
using MessageDataRequests = QMap<MsgId, MessageDataRequest>; using MessageDataRequests = base::flat_map<MsgId, MessageDataRequest>;
using SharedMediaType = Storage::SharedMediaType; using SharedMediaType = Storage::SharedMediaType;
struct StickersByEmoji { struct StickersByEmoji {
@ -460,8 +461,11 @@ private:
ChannelData *channel, ChannelData *channel,
mtpRequestId requestId); mtpRequestId requestId);
QVector<MTPInputMessage> collectMessageIds(const MessageDataRequests &requests); [[nodiscard]] QVector<MTPInputMessage> collectMessageIds(
MessageDataRequests *messageDataRequests(ChannelData *channel, bool onlyExisting = false); const MessageDataRequests &requests);
[[nodiscard]] MessageDataRequests *messageDataRequests(
ChannelData *channel,
bool onlyExisting = false);
void gotChatFull( void gotChatFull(
not_null<PeerData*> peer, not_null<PeerData*> peer,
@ -580,7 +584,9 @@ private:
base::flat_map<QString, int> _modifyRequests; base::flat_map<QString, int> _modifyRequests;
MessageDataRequests _messageDataRequests; MessageDataRequests _messageDataRequests;
QMap<ChannelData*, MessageDataRequests> _channelMessageDataRequests; base::flat_map<
ChannelData*,
MessageDataRequests> _channelMessageDataRequests;
SingleQueuedInvokation _messageDataResolveDelayed; SingleQueuedInvokation _messageDataResolveDelayed;
using PeerRequests = QMap<PeerData*, mtpRequestId>; using PeerRequests = QMap<PeerData*, mtpRequestId>;

View file

@ -1452,7 +1452,7 @@ void RevokePublicLinkBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
void RevokePublicLinkBox::Inner::paintEvent(QPaintEvent *e) { void RevokePublicLinkBox::Inner::paintEvent(QPaintEvent *e) {
Painter p(this); Painter p(this);
p.translate(0, _rowsTop); p.translate(0, _rowsTop);
for_const (auto &row, _rows) { for (const auto &row : _rows) {
paintChat(p, row, (row.peer == _selected)); paintChat(p, row, (row.peer == _selected));
p.translate(0, _rowHeight); p.translate(0, _rowHeight);
} }

View file

@ -470,7 +470,7 @@ void StickersBox::getArchivedDone(
auto addedSet = false; auto addedSet = false;
auto changedSets = false; auto changedSets = false;
for_const (const auto &stickerSet, stickers.vsets().v) { for (const auto &stickerSet : stickers.vsets().v) {
const MTPDstickerSet *setData = nullptr; const MTPDstickerSet *setData = nullptr;
switch (stickerSet.type()) { switch (stickerSet.type()) {
case mtpc_stickerSetCovered: { case mtpc_stickerSetCovered: {
@ -2291,7 +2291,7 @@ int StickersBox::Inner::getRowIndex(uint64 setId) const {
} }
void StickersBox::Inner::setFullOrder(const StickersSetsOrder &order) { void StickersBox::Inner::setFullOrder(const StickersSetsOrder &order) {
for_const (auto setId, order) { for (const auto setId : order) {
auto index = getRowIndex(setId); auto index = getRowIndex(setId);
if (index >= 0) { if (index >= 0) {
auto row = std::move(_rows[index]); auto row = std::move(_rows[index]);

View file

@ -379,9 +379,12 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) {
bool listAllSuggestions = _filter.isEmpty(); bool listAllSuggestions = _filter.isEmpty();
if (_addInlineBots) { if (_addInlineBots) {
for_const (auto user, cRecentInlineBots()) { for (const auto user : cRecentInlineBots()) {
if (user->isInaccessible()) continue; if (user->isInaccessible()
if (!listAllSuggestions && filterNotPassedByUsername(user)) continue; || (!listAllSuggestions
&& filterNotPassedByUsername(user))) {
continue;
}
mrows.push_back({ user }); mrows.push_back({ user });
++recentInlineBots; ++recentInlineBots;
} }

View file

@ -32,12 +32,6 @@ inline bool in_range(Value &&value, From &&from, Till &&till) {
} // namespace base } // 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<T*> 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; static const int32 ScrollMax = INT_MAX;
extern uint64 _SharedMemoryLocation[]; extern uint64 _SharedMemoryLocation[];

View file

@ -126,7 +126,7 @@ private:
using HistoryDrafts = base::flat_map<DraftKey, std::unique_ptr<Draft>>; using HistoryDrafts = base::flat_map<DraftKey, std::unique_ptr<Draft>>;
inline bool draftStringIsEmpty(const QString &text) { inline bool draftStringIsEmpty(const QString &text) {
for_const (auto ch, text) { for (const auto ch : text) {
if (!ch.isSpace()) { if (!ch.isSpace()) {
return false; return false;
} }

View file

@ -182,10 +182,12 @@ private:
not_null<ChannelData*> _channel; not_null<ChannelData*> _channel;
QPointer<Ui::Checkbox> _allFlags; QPointer<Ui::Checkbox> _allFlags;
QMap<MTPDchannelAdminLogEventsFilter::Flags, QPointer<Ui::Checkbox>> _filterFlags; base::flat_map<
MTPDchannelAdminLogEventsFilter::Flags,
QPointer<Ui::Checkbox>> _filterFlags;
QPointer<Ui::Checkbox> _allUsers; QPointer<Ui::Checkbox> _allUsers;
QMap<not_null<UserData*>, QPointer<UserCheckbox>> _admins; base::flat_map<not_null<UserData*>, QPointer<UserCheckbox>> _admins;
bool _restoringInvariant = false; bool _restoringInvariant = false;
struct Row { struct Row {
@ -224,7 +226,7 @@ void FilterBox::Inner::createAllActionsCheckbox(const FilterValue &filter) {
) | rpl::start_with_next([=](bool checked) { ) | rpl::start_with_next([=](bool checked) {
if (!std::exchange(_restoringInvariant, true)) { if (!std::exchange(_restoringInvariant, true)) {
auto allChecked = _allFlags->checked(); auto allChecked = _allFlags->checked();
for_const (auto &&checkbox, _filterFlags) { for (const auto &[flag, checkbox] : _filterFlags) {
checkbox->setChecked(allChecked); checkbox->setChecked(allChecked);
} }
_restoringInvariant = false; _restoringInvariant = false;
@ -241,12 +243,12 @@ void FilterBox::Inner::createActionsCheckboxes(const FilterValue &filter) {
auto addFlag = [this, &filter](Flags flag, QString &&text) { auto addFlag = [this, &filter](Flags flag, QString &&text) {
auto checked = (filter.flags == 0) || (filter.flags & flag); auto checked = (filter.flags == 0) || (filter.flags & flag);
auto checkbox = addRow(object_ptr<Ui::Checkbox>(this, std::move(text), checked, st::defaultBoxCheckbox), st::adminLogFilterLittleSkip); auto checkbox = addRow(object_ptr<Ui::Checkbox>(this, std::move(text), checked, st::defaultBoxCheckbox), st::adminLogFilterLittleSkip);
_filterFlags.insert(flag, checkbox); _filterFlags[flag] = checkbox;
checkbox->checkedChanges( checkbox->checkedChanges(
) | rpl::start_with_next([=](bool checked) { ) | rpl::start_with_next([=](bool checked) {
if (!std::exchange(_restoringInvariant, true)) { if (!std::exchange(_restoringInvariant, true)) {
auto allChecked = true; auto allChecked = true;
for_const (auto &&checkbox, _filterFlags) { for (const auto &[flag, checkbox] : _filterFlags) {
if (!checkbox->checked()) { if (!checkbox->checked()) {
allChecked = false; allChecked = false;
break; break;
@ -285,7 +287,7 @@ void FilterBox::Inner::createAllUsersCheckbox(const FilterValue &filter) {
) | rpl::start_with_next([=](bool checked) { ) | rpl::start_with_next([=](bool checked) {
if (!std::exchange(_restoringInvariant, true)) { if (!std::exchange(_restoringInvariant, true)) {
auto allChecked = _allUsers->checked(); auto allChecked = _allUsers->checked();
for_const (auto &&checkbox, _admins) { for (const auto &[user, checkbox] : _admins) {
checkbox->setChecked(allChecked); checkbox->setChecked(allChecked);
} }
_restoringInvariant = false; _restoringInvariant = false;
@ -297,14 +299,16 @@ void FilterBox::Inner::createAllUsersCheckbox(const FilterValue &filter) {
} }
void FilterBox::Inner::createAdminsCheckboxes(const std::vector<not_null<UserData*>> &admins, const FilterValue &filter) { void FilterBox::Inner::createAdminsCheckboxes(const std::vector<not_null<UserData*>> &admins, const FilterValue &filter) {
for (auto user : admins) { for (const auto user : admins) {
auto checked = filter.allUsers || base::contains(filter.admins, user); const auto checked = filter.allUsers || base::contains(filter.admins, user);
auto checkbox = addRow(object_ptr<UserCheckbox>(this, user, checked), st::adminLogFilterLittleSkip); const auto checkbox = addRow(
object_ptr<UserCheckbox>(this, user, checked),
st::adminLogFilterLittleSkip);
checkbox->checkedChanges( checkbox->checkedChanges(
) | rpl::start_with_next([=](bool checked) { ) | rpl::start_with_next([=](bool checked) {
if (!std::exchange(_restoringInvariant, true)) { if (!std::exchange(_restoringInvariant, true)) {
auto allChecked = true; auto allChecked = true;
for_const (auto &&checkbox, _admins) { for (const auto &[user, checkbox] : _admins) {
if (!checkbox->checked()) { if (!checkbox->checked()) {
allChecked = false; allChecked = false;
break; break;
@ -319,13 +323,13 @@ void FilterBox::Inner::createAdminsCheckboxes(const std::vector<not_null<UserDat
} }
} }
}, checkbox->lifetime()); }, checkbox->lifetime());
_admins.insert(user, checkbox); _admins[user] = checkbox;
} }
} }
bool FilterBox::Inner::canSave() const { bool FilterBox::Inner::canSave() const {
for (auto i = _filterFlags.cbegin(), e = _filterFlags.cend(); i != e; ++i) { for (const auto &[flag, checkbox] : _filterFlags) {
if (i.value()->checked()) { if (checkbox->checked()) {
return true; return true;
} }
} }
@ -335,9 +339,9 @@ bool FilterBox::Inner::canSave() const {
FilterValue FilterBox::Inner::filter() const { FilterValue FilterBox::Inner::filter() const {
auto result = FilterValue(); auto result = FilterValue();
auto allChecked = true; auto allChecked = true;
for (auto i = _filterFlags.cbegin(), e = _filterFlags.cend(); i != e; ++i) { for (const auto &[flag, checkbox] : _filterFlags) {
if (i.value()->checked()) { if (checkbox->checked()) {
result.flags |= i.key(); result.flags |= flag;
} else { } else {
allChecked = false; allChecked = false;
} }
@ -348,9 +352,9 @@ FilterValue FilterBox::Inner::filter() const {
result.allUsers = _allUsers->checked(); result.allUsers = _allUsers->checked();
if (!result.allUsers) { if (!result.allUsers) {
result.admins.reserve(_admins.size()); result.admins.reserve(_admins.size());
for (auto i = _admins.cbegin(), e = _admins.cend(); i != e; ++i) { for (const auto &[user, checkbox] : _admins) {
if (i.value()->checked()) { if (checkbox->checked()) {
result.admins.push_back(i.key()); result.admins.push_back(user);
} }
} }
} }

View file

@ -549,7 +549,7 @@ void ReplyKeyboard::resize(int width, int height) {
int widthForText = widthForButtons; int widthForText = widthForButtons;
int widthOfText = 0; int widthOfText = 0;
int maxMinButtonWidth = 0; int maxMinButtonWidth = 0;
for_const (auto &button, row) { for (const auto &button : row) {
widthOfText += qMax(button.text.maxWidth(), 1); widthOfText += qMax(button.text.maxWidth(), 1);
int minButtonWidth = _st->minButtonWidth(button.type); int minButtonWidth = _st->minButtonWidth(button.type);
widthForText -= minButtonWidth; widthForText -= minButtonWidth;
@ -559,7 +559,7 @@ void ReplyKeyboard::resize(int width, int height) {
bool enough = (widthForButtons - s * maxMinButtonWidth) >= widthOfText; bool enough = (widthForButtons - s * maxMinButtonWidth) >= widthOfText;
float64 x = 0; float64 x = 0;
for (Button &button : row) { for (auto &button : row) {
int buttonw = qMax(button.text.maxWidth(), 1); int buttonw = qMax(button.text.maxWidth(), 1);
float64 textw = buttonw, minw = _st->minButtonWidth(button.type); float64 textw = buttonw, minw = _st->minButtonWidth(button.type);
float64 w = textw; float64 w = textw;
@ -587,10 +587,10 @@ void ReplyKeyboard::resize(int width, int height) {
} }
bool ReplyKeyboard::isEnoughSpace(int width, const style::BotKeyboardButton &st) const { 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 s = row.size();
int widthLeft = width - ((s - 1) * st.margin + s * 2 * st.padding); 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); widthLeft -= qMax(button.text.maxWidth(), 1);
if (widthLeft < 0) { if (widthLeft < 0) {
if (row.size() > 3) { if (row.size() > 3) {
@ -662,8 +662,8 @@ void ReplyKeyboard::paint(
ClickHandlerPtr ReplyKeyboard::getLink(QPoint point) const { ClickHandlerPtr ReplyKeyboard::getLink(QPoint point) const {
Assert(_width > 0); Assert(_width > 0);
for_const (auto &row, _rows) { for (const auto &row : _rows) {
for_const (auto &button, row) { for (const auto &button : row) {
QRect rect(button.rect); QRect rect(button.rect);
// just ignore the buttons that didn't layout well // just ignore the buttons that didn't layout well

View file

@ -951,7 +951,7 @@ void HistoryService::setServiceText(const PreparedText &prepared) {
prepared.text, prepared.text,
Ui::ItemTextServiceOptions()); Ui::ItemTextServiceOptions());
auto linkIndex = 0; auto linkIndex = 0;
for_const (auto &link, prepared.links) { for (const auto &link : prepared.links) {
// Link indices start with 1. // Link indices start with 1.
_text.setLink(++linkIndex, link); _text.setLink(++linkIndex, link);
} }

View file

@ -233,7 +233,7 @@ void GroupMembersWidget::sortMembers() {
void GroupMembersWidget::updateOnlineCount() { void GroupMembersWidget::updateOnlineCount() {
bool onlyMe = true; bool onlyMe = true;
int newOnlineCount = 0; int newOnlineCount = 0;
for_const (auto item, items()) { for (const auto item : items()) {
auto member = getMember(item); auto member = getMember(item);
auto user = member->user(); auto user = member->user();
auto isOnline = !user->isBot() && Data::OnlineTextActive(member->onlineTill, _now); auto isOnline = !user->isBot() && Data::OnlineTextActive(member->onlineTill, _now);
@ -433,7 +433,7 @@ void GroupMembersWidget::updateOnlineDisplay() {
_now = base::unixtime::now(); _now = base::unixtime::now();
bool changed = false; bool changed = false;
for_const (auto item, items()) { for (const auto item : items()) {
if (!item->statusHasOnlineColor) { if (!item->statusHasOnlineColor) {
if (!item->peer->isSelf()) { if (!item->peer->isSelf()) {
continue; continue;

View file

@ -63,8 +63,9 @@ void PeerListWidget::paintContents(Painter &p) {
auto left = getListLeft(); auto left = getListLeft();
auto top = getListTop(); auto top = getListTop();
auto from = floorclamp(_visibleTop - top, _st.height, 0, _items.size()); const auto count = int(_items.size());
auto to = ceilclamp(_visibleBottom - top, _st.height, 0, _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) { for (auto i = from; i < to; ++i) {
auto y = top + i * _st.height; auto y = top + i * _st.height;
auto selected = (_pressed >= 0) ? (i == _pressed) : (i == _selected); auto selected = (_pressed >= 0) ? (i == _pressed) : (i == _selected);
@ -147,7 +148,7 @@ void PeerListWidget::mousePressEvent(QMouseEvent *e) {
_pressed = _selected; _pressed = _selected;
_pressedRemove = _selectedRemove; _pressedRemove = _selectedRemove;
if (_pressed >= 0 && !_pressedRemove) { if (_pressed >= 0 && !_pressedRemove) {
auto item = _items[_pressed]; const auto item = _items[_pressed];
if (!item->ripple) { if (!item->ripple) {
auto memberRowWidth = rowWidth(); auto memberRowWidth = rowWidth();
auto mask = Ui::RippleAnimation::rectMask(QSize(memberRowWidth, _st.height)); 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 pressed = std::exchange(_pressed, -1);
auto pressedRemove = base::take(_pressedRemove); auto pressedRemove = base::take(_pressedRemove);
if (pressed >= 0 && pressed < _items.size()) { if (pressed >= 0 && pressed < _items.size()) {
if (auto &ripple = _items[pressed]->ripple) { if (const auto &ripple = _items[pressed]->ripple) {
ripple->lastStop(); ripple->lastStop();
} }
if (pressed == _selected && pressedRemove == _selectedRemove && button == Qt::LeftButton) { if (pressed == _selected && pressedRemove == _selectedRemove && button == Qt::LeftButton) {
@ -274,7 +275,7 @@ void PeerListWidget::preloadPhotos() {
} }
void PeerListWidget::refreshVisibility() { void PeerListWidget::refreshVisibility() {
setVisible(!_items.isEmpty()); setVisible(!_items.empty());
} }
} // namespace Profile } // namespace Profile

View file

@ -52,7 +52,7 @@ public:
int getListLeft() const; int getListLeft() const;
const QList<Item*> &items() const { const std::vector<Item*> &items() const {
return _items; return _items;
} }
int itemsCount() const { int itemsCount() const {
@ -129,7 +129,7 @@ private:
Fn<void(PeerData*)> _removedCallback; Fn<void(PeerData*)> _removedCallback;
Fn<void(Item*)> _updateItemCallback; Fn<void(Item*)> _updateItemCallback;
QList<Item*> _items; std::vector<Item*> _items;
int _visibleTop = 0; int _visibleTop = 0;
int _visibleBottom = 0; int _visibleBottom = 0;

View file

@ -98,7 +98,7 @@ private:
int _oldCount; int _oldCount;
QVector<SampleWidget*> _cornerSamples[4]; std::vector<SampleWidget*> _cornerSamples[4];
}; };
@ -350,7 +350,8 @@ void NotificationsCount::setOverCorner(ScreenCorner corner) {
if (corner == _overCorner) { if (corner == _overCorner) {
return; return;
} }
for_const (auto widget, _cornerSamples[static_cast<int>(_overCorner)]) { const auto index = static_cast<int>(_overCorner);
for (const auto widget : _cornerSamples[index]) {
widget->hideFast(); widget->hideFast();
} }
} else { } else {
@ -362,7 +363,7 @@ void NotificationsCount::setOverCorner(ScreenCorner corner) {
_overCorner = corner; _overCorner = corner;
auto &samples = _cornerSamples[static_cast<int>(_overCorner)]; auto &samples = _cornerSamples[static_cast<int>(_overCorner)];
auto samplesAlready = samples.size(); auto samplesAlready = int(samples.size());
auto samplesNeeded = _oldCount; auto samplesNeeded = _oldCount;
auto samplesLeave = qMin(samplesAlready, samplesNeeded); auto samplesLeave = qMin(samplesAlready, samplesNeeded);
for (int i = 0; i != samplesLeave; ++i) { for (int i = 0; i != samplesLeave; ++i) {
@ -394,8 +395,8 @@ void NotificationsCount::clearOverCorner() {
Core::App().notifications().notifySettingsChanged( Core::App().notifications().notifySettingsChanged(
ChangeType::DemoIsHidden); ChangeType::DemoIsHidden);
for_const (const auto &samples, _cornerSamples) { for (const auto &samples : _cornerSamples) {
for_const (const auto widget, samples) { for (const auto widget : samples) {
widget->hideFast(); widget->hideFast();
} }
} }
@ -426,8 +427,8 @@ void NotificationsCount::mouseReleaseEvent(QMouseEvent *e) {
} }
NotificationsCount::~NotificationsCount() { NotificationsCount::~NotificationsCount() {
for_const (auto &samples, _cornerSamples) { for (const auto &samples : _cornerSamples) {
for_const (auto widget, samples) { for (const auto widget : samples) {
widget->detach(); widget->detach();
} }
} }

View file

@ -2258,7 +2258,7 @@ void Account::readInstalledMasks() {
} }
void Account::writeSavedGifs() { void Account::writeSavedGifs() {
auto &saved = _owner->session().data().stickers().savedGifs(); const auto &saved = _owner->session().data().stickers().savedGifs();
if (saved.isEmpty()) { if (saved.isEmpty()) {
if (_savedGifsKey) { if (_savedGifsKey) {
ClearKey(_savedGifsKey, _basePath); ClearKey(_savedGifsKey, _basePath);
@ -2267,7 +2267,7 @@ void Account::writeSavedGifs() {
} }
} else { } else {
quint32 size = sizeof(quint32); // count quint32 size = sizeof(quint32); // count
for_const (auto gif, saved) { for (const auto gif : saved) {
size += Serialize::Document::sizeInStream(gif); size += Serialize::Document::sizeInStream(gif);
} }
@ -2277,7 +2277,7 @@ void Account::writeSavedGifs() {
} }
EncryptedDescriptor data(size); EncryptedDescriptor data(size);
data.stream << quint32(saved.size()); data.stream << quint32(saved.size());
for_const (auto gif, saved) { for (const auto gif : saved) {
Serialize::Document::writeToStream(data.stream, gif); Serialize::Document::writeToStream(data.stream, gif);
} }
FileWriteDescriptor file(_savedGifsKey, _basePath); FileWriteDescriptor file(_savedGifsKey, _basePath);

View file

@ -188,7 +188,7 @@ QRect MultiSelect::Item::paintArea(int outerWidth) const {
return rect(); return rect();
} }
auto yMin = 0, yMax = 0; auto yMin = 0, yMax = 0;
for_const (auto &copy, _copies) { for (const auto &copy : _copies) {
accumulate_max(yMax, copy.y); accumulate_max(yMax, copy.y);
if (yMin) { if (yMin) {
accumulate_min(yMin, copy.y); accumulate_min(yMin, copy.y);
@ -671,7 +671,7 @@ void MultiSelect::Inner::computeItemsGeometry(int newWidth) {
auto itemTop = 0; auto itemTop = 0;
auto widthLeft = newWidth; auto widthLeft = newWidth;
auto maxVisiblePadding = qMax(_st.padding.left(), _st.padding.right()); auto maxVisiblePadding = qMax(_st.padding.left(), _st.padding.right());
for_const (auto &item, _items) { for (const auto &item : _items) {
auto itemWidth = item->getWidth(); auto itemWidth = item->getWidth();
Assert(itemWidth <= newWidth); Assert(itemWidth <= newWidth);
if (itemWidth > widthLeft) { if (itemWidth > widthLeft) {
@ -721,7 +721,7 @@ void MultiSelect::Inner::finishHeightAnimation() {
} }
void MultiSelect::Inner::setItemText(uint64 itemId, const QString &text) { void MultiSelect::Inner::setItemText(uint64 itemId, const QString &text) {
for_const (auto &item, _items) { for (const auto &item : _items) {
if (item->id() == itemId) { if (item->id() == itemId) {
item->setText(text); item->setText(text);
updateItemsGeometry(); updateItemsGeometry();
@ -783,7 +783,7 @@ int MultiSelect::Inner::getItemsCount() const {
QVector<uint64> MultiSelect::Inner::getItems() const { QVector<uint64> MultiSelect::Inner::getItems() const {
auto result = QVector<uint64>(); auto result = QVector<uint64>();
result.reserve(_items.size()); result.reserve(_items.size());
for_const (auto &item, _items) { for (const auto &item : _items) {
result.push_back(item->id()); result.push_back(item->id());
} }
return result; return result;

View file

@ -98,7 +98,7 @@ QPixmap Manager::hiddenUserpicPlaceholder() const {
} }
bool Manager::hasReplyingNotification() const { bool Manager::hasReplyingNotification() const {
for_const (auto &notification, _notifications) { for (const auto &notification : _notifications) {
if (notification->isReplying()) { if (notification->isReplying()) {
return true; return true;
} }
@ -110,7 +110,7 @@ void Manager::settingsChanged(ChangeType change) {
if (change == ChangeType::Corner) { if (change == ChangeType::Corner) {
auto startPosition = notificationStartPosition(); auto startPosition = notificationStartPosition();
auto shiftDirection = notificationShiftDirection(); auto shiftDirection = notificationShiftDirection();
for_const (auto &notification, _notifications) { for (const auto &notification : _notifications) {
notification->updatePosition(startPosition, shiftDirection); notification->updatePosition(startPosition, shiftDirection);
} }
if (_hideAll) { if (_hideAll) {
@ -142,7 +142,7 @@ void Manager::settingsChanged(ChangeType change) {
} }
void Manager::demoMasterOpacityCallback() { void Manager::demoMasterOpacityCallback() {
for_const (auto &notification, _notifications) { for (const auto &notification : _notifications) {
notification->updateOpacity(); notification->updateOpacity();
} }
if (_hideAll) { if (_hideAll) {
@ -173,7 +173,7 @@ void Manager::checkLastInput() {
void Manager::startAllHiding() { void Manager::startAllHiding() {
if (!hasReplyingNotification()) { if (!hasReplyingNotification()) {
int notHidingCount = 0; int notHidingCount = 0;
for_const (auto &notification, _notifications) { for (const auto &notification : _notifications) {
if (notification->isShowing()) { if (notification->isShowing()) {
++notHidingCount; ++notHidingCount;
} else { } else {
@ -188,7 +188,7 @@ void Manager::startAllHiding() {
} }
void Manager::stopAllHiding() { void Manager::stopAllHiding() {
for_const (auto &notification, _notifications) { for (const auto &notification : _notifications) {
notification->stopHiding(); notification->stopHiding();
} }
if (_hideAll) { if (_hideAll) {
@ -400,7 +400,7 @@ void Manager::doClearFromItem(not_null<HistoryItem*> item) {
}), _queuedNotifications.cend()); }), _queuedNotifications.cend());
auto showNext = false; auto showNext = false;
for_const (auto &notification, _notifications) { for (const auto &notification : _notifications) {
if (notification->unlinkItem(item)) { if (notification->unlinkItem(item)) {
showNext = true; showNext = true;
} }
@ -424,7 +424,7 @@ bool Manager::doSkipFlashBounce() const {
} }
void Manager::doUpdateAll() { void Manager::doUpdateAll() {
for_const (auto &notification, _notifications) { for (const auto &notification : _notifications) {
notification->updateNotifyDisplay(); notification->updateNotifyDisplay();
} }
} }

View file

@ -55,11 +55,11 @@ public:
fillSearchIndex(); fillSearchIndex();
} }
const OrderedSet<QString> &searchWords() const { const base::flat_set<QString> &searchWords() const {
return _searchWords; return _searchWords;
} }
bool searchWordsContain(const QString &needle) const { bool searchWordsContain(const QString &needle) const {
for_const (auto &word, _searchWords) { for (const auto &word : _searchWords) {
if (word.startsWith(needle)) { if (word.startsWith(needle)) {
return true; return true;
} }
@ -67,7 +67,7 @@ public:
return false; return false;
} }
const OrderedSet<QChar> &searchStartChars() const { const base::flat_set<QChar> &searchStartChars() const {
return _searchStartChars; return _searchStartChars;
} }
@ -106,8 +106,8 @@ private:
QString _valueString; QString _valueString;
Ui::Text::String _description = { st::windowMinWidth / 2 }; Ui::Text::String _description = { st::windowMinWidth / 2 };
OrderedSet<QString> _searchWords; base::flat_set<QString> _searchWords;
OrderedSet<QChar> _searchStartChars; base::flat_set<QChar> _searchStartChars;
int _top = 0; int _top = 0;
int _height = 0; int _height = 0;
@ -154,11 +154,16 @@ void EditorBlock::Row::fillValueString() {
void EditorBlock::Row::fillSearchIndex() { void EditorBlock::Row::fillSearchIndex() {
_searchWords.clear(); _searchWords.clear();
_searchStartChars.clear(); _searchStartChars.clear();
auto toIndex = _name + ' ' + _copyOf + ' ' + TextUtilities::RemoveAccents(_description.toString()) + ' ' + _valueString; const auto toIndex = _name
auto words = toIndex.toLower().split(SearchSplitter, base::QStringSkipEmptyParts); + ' ' + _copyOf
for_const (auto &word, words) { + ' ' + TextUtilities::RemoveAccents(_description.toString())
_searchWords.insert(word); + ' ' + _valueString;
_searchStartChars.insert(word[0]); 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(); if (!query.isEmpty()) resetSearch();
auto index = findRowIndex(&row); auto index = findRowIndex(&row);
for_const (auto ch, row.searchStartChars()) { for (const auto ch : row.searchStartChars()) {
_searchIndex[ch].insert(index); _searchIndex[ch].insert(index);
} }
@ -264,12 +269,12 @@ void EditorBlock::removeFromSearch(const Row &row) {
if (!query.isEmpty()) resetSearch(); if (!query.isEmpty()) resetSearch();
auto index = findRowIndex(&row); auto index = findRowIndex(&row);
for_const (auto ch, row.searchStartChars()) { for (const auto ch : row.searchStartChars()) {
auto it = _searchIndex.find(ch); const auto i = _searchIndex.find(ch);
if (it != _searchIndex.cend()) { if (i != end(_searchIndex)) {
it->remove(index); i->second.remove(index);
if (it->isEmpty()) { if (i->second.empty()) {
_searchIndex.erase(it); _searchIndex.erase(i);
} }
} }
} }
@ -339,7 +344,9 @@ void EditorBlock::scrollToSelected() {
} }
void EditorBlock::searchByQuery(QString query) { void EditorBlock::searchByQuery(QString query) {
auto words = TextUtilities::PrepareSearchWords(query, &SearchSplitter); const auto words = TextUtilities::PrepareSearchWords(
query,
&SearchSplitter);
query = words.isEmpty() ? QString() : words.join(' '); query = words.isEmpty() ? QString() : words.join(' ');
if (_searchQuery != query) { if (_searchQuery != query) {
setSelected(-1); setSelected(-1);
@ -348,28 +355,28 @@ void EditorBlock::searchByQuery(QString query) {
_searchQuery = query; _searchQuery = query;
_searchResults.clear(); _searchResults.clear();
auto toFilter = OrderedSet<int>(); auto toFilter = (base::flat_set<int>*)nullptr;
for_const (auto &word, words) { for (const auto &word : words) {
if (word.isEmpty()) continue; if (word.isEmpty()) continue;
auto testToFilter = _searchIndex.value(word[0]); const auto i = _searchIndex.find(word[0]);
if (testToFilter.isEmpty()) { if (i == end(_searchIndex) || i->second.empty()) {
toFilter.clear(); toFilter = nullptr;
break; break;
} else if (toFilter.isEmpty() || testToFilter.size() < toFilter.size()) { } else if (!toFilter || i->second.size() < toFilter->size()) {
toFilter = testToFilter; toFilter = &i->second;
} }
} }
if (!toFilter.isEmpty()) { if (toFilter) {
auto allWordsFound = [&words](const Row &row) { const auto allWordsFound = [&](const Row &row) {
for_const (auto &word, words) { for (const auto &word : words) {
if (!row.searchWordsContain(word)) { if (!row.searchWordsContain(word)) {
return false; return false;
} }
} }
return true; return true;
}; };
for_const (auto index, toFilter) { for (const auto index : *toFilter) {
if (allWordsFound(_data[index])) { if (allWordsFound(_data[index])) {
_searchResults.push_back(index); _searchResults.push_back(index);
} }
@ -423,7 +430,7 @@ void EditorBlock::sortByDistance(const QColor &to) {
template <typename Callback> template <typename Callback>
void EditorBlock::enumerateRows(Callback callback) { void EditorBlock::enumerateRows(Callback callback) {
if (isSearch()) { if (isSearch()) {
for_const (auto index, _searchResults) { for (const auto index : _searchResults) {
if (!callback(_data[index])) { if (!callback(_data[index])) {
break; break;
} }
@ -440,7 +447,7 @@ void EditorBlock::enumerateRows(Callback callback) {
template <typename Callback> template <typename Callback>
void EditorBlock::enumerateRows(Callback callback) const { void EditorBlock::enumerateRows(Callback callback) const {
if (isSearch()) { if (isSearch()) {
for_const (auto index, _searchResults) { for (const auto index : _searchResults) {
if (!callback(_data[index])) { if (!callback(_data[index])) {
break; break;
} }

View file

@ -144,8 +144,8 @@ private:
QMap<QString, int> _indices; QMap<QString, int> _indices;
QString _searchQuery; QString _searchQuery;
QVector<int> _searchResults; std::vector<int> _searchResults;
QMap<QChar, OrderedSet<int>> _searchIndex; base::flat_map<QChar, base::flat_set<int>> _searchIndex;
int _selected = -1; int _selected = -1;
int _pressed = -1; int _pressed = -1;