Use base::flat_map for pointer keys
This commit is contained in:
parent
cdf0512515
commit
4ffe1d3acc
4 changed files with 22 additions and 22 deletions
|
@ -2600,7 +2600,7 @@ void ApiWrap::clearWebPageRequests() {
|
|||
void ApiWrap::resolveWebPages() {
|
||||
auto ids = QVector<MTPInputMessage>(); // temp_req_id = -1
|
||||
using IndexAndMessageIds = QPair<int32, QVector<MTPInputMessage>>;
|
||||
using MessageIdsByChannel = QMap<ChannelData*, IndexAndMessageIds>;
|
||||
using MessageIdsByChannel = base::flat_map<ChannelData*, IndexAndMessageIds>;
|
||||
MessageIdsByChannel idsByChannel; // temp_req_id = -index - 2
|
||||
|
||||
ids.reserve(_webPagesPending.size());
|
||||
|
@ -2617,18 +2617,18 @@ void ApiWrap::resolveWebPages() {
|
|||
auto channel = item->history()->peer->asChannel();
|
||||
auto channelMap = idsByChannel.find(channel);
|
||||
if (channelMap == idsByChannel.cend()) {
|
||||
channelMap = idsByChannel.insert(
|
||||
channelMap = idsByChannel.emplace(
|
||||
channel,
|
||||
IndexAndMessageIds(
|
||||
idsByChannel.size(),
|
||||
QVector<MTPInputMessage>(
|
||||
1,
|
||||
MTP_inputMessageID(MTP_int(item->id)))));
|
||||
MTP_inputMessageID(MTP_int(item->id))))).first;
|
||||
} else {
|
||||
channelMap.value().second.push_back(
|
||||
channelMap->second.second.push_back(
|
||||
MTP_inputMessageID(MTP_int(item->id)));
|
||||
}
|
||||
i.value() = -channelMap.value().first - 2;
|
||||
i.value() = -channelMap->second.first - 2;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -2648,10 +2648,10 @@ void ApiWrap::resolveWebPages() {
|
|||
}
|
||||
QVector<mtpRequestId> reqsByIndex(idsByChannel.size(), 0);
|
||||
for (auto i = idsByChannel.cbegin(), e = idsByChannel.cend(); i != e; ++i) {
|
||||
reqsByIndex[i.value().first] = request(MTPchannels_GetMessages(
|
||||
i.key()->inputChannel,
|
||||
MTP_vector<MTPInputMessage>(i.value().second)
|
||||
)).done([=, channel = i.key()](
|
||||
reqsByIndex[i->second.first] = request(MTPchannels_GetMessages(
|
||||
i->first->inputChannel,
|
||||
MTP_vector<MTPInputMessage>(i->second.second)
|
||||
)).done([=, channel = i->first](
|
||||
const MTPmessages_Messages &result,
|
||||
mtpRequestId requestId) {
|
||||
gotWebPages(channel, result, requestId);
|
||||
|
|
|
@ -436,7 +436,7 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) {
|
|||
} else if (_type == Type::BotCommands) {
|
||||
bool listAllSuggestions = _filter.isEmpty();
|
||||
bool hasUsername = _filter.indexOf('@') > 0;
|
||||
QMap<UserData*, bool> bots;
|
||||
base::flat_map<UserData*, bool> bots;
|
||||
int32 cnt = 0;
|
||||
if (_chat) {
|
||||
if (_chat->noParticipantInfo()) {
|
||||
|
@ -451,7 +451,7 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) {
|
|||
if (user->botInfo->commands.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
bots.insert(user, true);
|
||||
bots.emplace(user, true);
|
||||
cnt += user->botInfo->commands.size();
|
||||
}
|
||||
}
|
||||
|
@ -460,7 +460,7 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) {
|
|||
_user->session().api().requestFullPeer(_user);
|
||||
}
|
||||
cnt = _user->botInfo->commands.size();
|
||||
bots.insert(_user, true);
|
||||
bots.emplace(_user, true);
|
||||
} else if (_channel && _channel->isMegagroup()) {
|
||||
if (_channel->mgInfo->bots.empty()) {
|
||||
if (!_channel->mgInfo->botStatus) {
|
||||
|
@ -476,7 +476,7 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) {
|
|||
if (user->botInfo->commands.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
bots.insert(user, true);
|
||||
bots.emplace(user, true);
|
||||
cnt += user->botInfo->commands.size();
|
||||
}
|
||||
}
|
||||
|
@ -510,9 +510,9 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!bots.isEmpty()) {
|
||||
for (QMap<UserData*, bool>::const_iterator i = bots.cbegin(), e = bots.cend(); i != e; ++i) {
|
||||
UserData *user = i.key();
|
||||
if (!bots.empty()) {
|
||||
for (auto i = bots.cbegin(), e = bots.cend(); i != e; ++i) {
|
||||
UserData *user = i->first;
|
||||
for (int32 j = 0, l = user->botInfo->commands.size(); j < l; ++j) {
|
||||
if (!listAllSuggestions) {
|
||||
QString toFilter = (hasUsername || botStatus == 0 || botStatus == 2) ? user->botInfo->commands.at(j).command + '@' + user->username : user->botInfo->commands.at(j).command;
|
||||
|
|
|
@ -140,7 +140,7 @@ void GroupMembersWidget::refreshUserOnline(UserData *user) {
|
|||
|
||||
_now = base::unixtime::now();
|
||||
|
||||
auto member = getMember(it.value());
|
||||
auto member = getMember(it->second);
|
||||
member->statusHasOnlineColor = !user->isBot()
|
||||
&& Data::OnlineTextActive(user->onlineTill, _now);
|
||||
member->onlineTill = user->onlineTill;
|
||||
|
@ -420,16 +420,16 @@ void GroupMembersWidget::setItemFlags(
|
|||
|
||||
auto GroupMembersWidget::computeMember(not_null<UserData*> user)
|
||||
-> not_null<Member*> {
|
||||
auto it = _membersByUser.constFind(user);
|
||||
auto it = _membersByUser.find(user);
|
||||
if (it == _membersByUser.cend()) {
|
||||
auto member = new Member(user);
|
||||
it = _membersByUser.insert(user, member);
|
||||
it = _membersByUser.emplace(user, member).first;
|
||||
member->statusHasOnlineColor = !user->isBot()
|
||||
&& Data::OnlineTextActive(user->onlineTill, _now);
|
||||
member->onlineTill = user->onlineTill;
|
||||
member->onlineForSort = Data::SortByOnlineValue(user, _now);
|
||||
}
|
||||
return it.value();
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void GroupMembersWidget::onUpdateOnlineDisplay() {
|
||||
|
@ -461,7 +461,7 @@ void GroupMembersWidget::onUpdateOnlineDisplay() {
|
|||
|
||||
GroupMembersWidget::~GroupMembersWidget() {
|
||||
auto members = base::take(_membersByUser);
|
||||
for_const (auto member, members) {
|
||||
for (const auto &[_, member] : members) {
|
||||
delete member;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ private:
|
|||
not_null<ChannelData*> megagroup);
|
||||
bool addUsersToEnd(not_null<ChannelData*> megagroup);
|
||||
|
||||
QMap<UserData*, Member*> _membersByUser;
|
||||
base::flat_map<UserData*, Member*> _membersByUser;
|
||||
bool _sortByOnline = false;
|
||||
TimeId _now = 0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue