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