Use WaitFreeHashSet where appropriate.

This commit is contained in:
levlam 2022-08-21 00:20:57 +03:00
parent 59a5f15a41
commit 092499a7c6
5 changed files with 22 additions and 26 deletions

View File

@ -11933,15 +11933,15 @@ void ContactsManager::on_update_user_full_need_phone_number_privacy_exception(
}
void ContactsManager::on_ignored_restriction_reasons_changed() {
for (auto user_id : restricted_user_ids_) {
restricted_user_ids_.foreach([&](const UserId &user_id) {
send_closure(G()->td(), &Td::send_update,
td_api::make_object<td_api::updateUser>(get_user_object(user_id, get_user(user_id))));
}
for (auto channel_id : restricted_channel_ids_) {
});
restricted_channel_ids_.foreach([&](const ChannelId &channel_id) {
send_closure(
G()->td(), &Td::send_update,
td_api::make_object<td_api::updateSupergroup>(get_supergroup_object(channel_id, get_channel(channel_id))));
}
});
}
void ContactsManager::on_set_profile_photo(tl_object_ptr<telegram_api::photos_photo> &&photo, int64 old_photo_id) {

View File

@ -51,6 +51,7 @@
#include "td/utils/StringBuilder.h"
#include "td/utils/Time.h"
#include "td/utils/WaitFreeHashMap.h"
#include "td/utils/WaitFreeHashSet.h"
#include <functional>
#include <memory>
@ -1720,7 +1721,7 @@ class ContactsManager final : public Actor {
WaitFreeHashMap<ChannelId, unique_ptr<Channel>, ChannelIdHash> channels_;
WaitFreeHashMap<ChannelId, unique_ptr<ChannelFull>, ChannelIdHash> channels_full_;
mutable FlatHashSet<ChannelId, ChannelIdHash> unknown_channels_;
FlatHashSet<ChannelId, ChannelIdHash> invalidated_channels_full_;
WaitFreeHashSet<ChannelId, ChannelIdHash> invalidated_channels_full_;
WaitFreeHashMap<ChannelId, FileSourceId, ChannelIdHash> channel_full_file_source_ids_;
WaitFreeHashMap<SecretChatId, unique_ptr<SecretChat>, SecretChatIdHash> secret_chats_;
@ -1839,8 +1840,8 @@ class ContactsManager final : public Actor {
WaitFreeHashMap<ChannelId, ChannelId, ChannelIdHash> linked_channel_ids_;
FlatHashSet<UserId, UserIdHash> restricted_user_ids_;
FlatHashSet<ChannelId, ChannelIdHash> restricted_channel_ids_;
WaitFreeHashSet<UserId, UserIdHash> restricted_user_ids_;
WaitFreeHashSet<ChannelId, ChannelIdHash> restricted_channel_ids_;
vector<Contact> next_all_imported_contacts_;
vector<size_t> imported_contacts_unique_id_;

View File

@ -78,6 +78,7 @@
#include "td/utils/Status.h"
#include "td/utils/StringBuilder.h"
#include "td/utils/WaitFreeHashMap.h"
#include "td/utils/WaitFreeHashSet.h"
#include <array>
#include <functional>
@ -1371,7 +1372,7 @@ class MessagesManager final : public Actor {
FlatHashMap<int32, MessageId> last_assigned_scheduled_message_id; // date -> message_id
FlatHashSet<MessageId, MessageIdHash> deleted_message_ids;
WaitFreeHashSet<MessageId, MessageIdHash> deleted_message_ids;
FlatHashSet<ScheduledServerMessageId, ScheduledServerMessageIdHash> deleted_scheduled_server_message_ids;
vector<std::pair<DialogId, MessageId>> pending_new_message_notifications;

View File

@ -1688,9 +1688,7 @@ void StickersManager::on_load_special_sticker_set(const SpecialStickerSetType &t
}
vector<FullMessageId> full_message_ids;
for (const auto &full_message_id : it->second) {
full_message_ids.push_back(full_message_id);
}
it->second.foreach([&](const FullMessageId &full_message_id) { full_message_ids.push_back(full_message_id); });
CHECK(!full_message_ids.empty());
for (const auto &full_message_id : full_message_ids) {
td_->messages_manager_->on_external_update_message_content(full_message_id);
@ -5172,9 +5170,8 @@ void StickersManager::try_update_animated_emoji_messages() {
(new_animated_sticker.first.is_valid() && new_sound_file_id != it.second->sound_file_id_)) {
it.second->animated_emoji_sticker_ = new_animated_sticker;
it.second->sound_file_id_ = new_sound_file_id;
for (const auto &full_message_id : it.second->full_message_ids_) {
full_message_ids.push_back(full_message_id);
}
it.second->full_message_ids_.foreach(
[&](const FullMessageId &full_message_id) { full_message_ids.push_back(full_message_id); });
}
}
for (const auto &full_message_id : full_message_ids) {
@ -5192,9 +5189,8 @@ void StickersManager::try_update_custom_emoji_messages(int64 custom_emoji_id) {
auto new_sticker_id = get_custom_animated_emoji_sticker_id(custom_emoji_id);
if (new_sticker_id != it->second->sticker_id_) {
it->second->sticker_id_ = new_sticker_id;
for (const auto &full_message_id : it->second->full_message_ids_) {
full_message_ids.push_back(full_message_id);
}
it->second->full_message_ids_.foreach(
[&](const FullMessageId &full_message_id) { full_message_ids.push_back(full_message_id); });
}
for (const auto &full_message_id : full_message_ids) {
td_->messages_manager_->on_external_update_message_content(full_message_id);
@ -5264,8 +5260,7 @@ void StickersManager::register_dice(const string &emoji, int32 value, FullMessag
LOG(INFO) << "Register dice " << emoji << " with value " << value << " from " << full_message_id << " from "
<< source;
bool is_inserted = dice_messages_[emoji].insert(full_message_id).second;
LOG_CHECK(is_inserted) << source << " " << emoji << " " << value << " " << full_message_id;
dice_messages_[emoji].insert(full_message_id);
if (!td::contains(dice_emojis_, emoji)) {
if (full_message_id.get_message_id().is_any_server() &&
@ -5334,8 +5329,7 @@ void StickersManager::register_emoji(const string &emoji, int64 custom_emoji_id,
get_custom_emoji_stickers({custom_emoji_id}, true, Promise<td_api::object_ptr<td_api::stickers>>());
}
}
bool is_inserted = emoji_messages.full_message_ids_.insert(full_message_id).second;
LOG_CHECK(is_inserted) << source << ' ' << custom_emoji_id << ' ' << full_message_id;
emoji_messages.full_message_ids_.insert(full_message_id);
return;
}
@ -5348,8 +5342,7 @@ void StickersManager::register_emoji(const string &emoji, int64 custom_emoji_id,
emoji_messages.animated_emoji_sticker_ = get_animated_emoji_sticker(emoji);
emoji_messages.sound_file_id_ = get_animated_emoji_sound_file_id(emoji);
}
bool is_inserted = emoji_messages.full_message_ids_.insert(full_message_id).second;
LOG_CHECK(is_inserted) << source << ' ' << emoji << ' ' << full_message_id;
emoji_messages.full_message_ids_.insert(full_message_id);
}
void StickersManager::unregister_emoji(const string &emoji, int64 custom_emoji_id, FullMessageId full_message_id,

View File

@ -34,6 +34,7 @@
#include "td/utils/Slice.h"
#include "td/utils/Status.h"
#include "td/utils/WaitFreeHashMap.h"
#include "td/utils/WaitFreeHashSet.h"
#include <memory>
#include <tuple>
@ -1002,17 +1003,17 @@ class StickersManager final : public Actor {
};
FlatHashMap<int32, unique_ptr<GiftPremiumMessages>> premium_gift_messages_;
FlatHashMap<string, FlatHashSet<FullMessageId, FullMessageIdHash>> dice_messages_;
FlatHashMap<string, WaitFreeHashSet<FullMessageId, FullMessageIdHash>> dice_messages_;
struct EmojiMessages {
FlatHashSet<FullMessageId, FullMessageIdHash> full_message_ids_;
WaitFreeHashSet<FullMessageId, FullMessageIdHash> full_message_ids_;
std::pair<FileId, int> animated_emoji_sticker_;
FileId sound_file_id_;
};
FlatHashMap<string, unique_ptr<EmojiMessages>> emoji_messages_;
struct CustomEmojiMessages {
FlatHashSet<FullMessageId, FullMessageIdHash> full_message_ids_;
WaitFreeHashSet<FullMessageId, FullMessageIdHash> full_message_ids_;
FileId sticker_id_;
};
FlatHashMap<int64, unique_ptr<CustomEmojiMessages>> custom_emoji_messages_;