Use td::contains and td::remove instead of std::find if possible.
GitOrigin-RevId: faa0863eb49ee8ce4c2138dfec022620f71d2f6a
This commit is contained in:
parent
e84e131efd
commit
918f6a0cfd
@ -754,8 +754,7 @@ void AnimationsManager::remove_saved_animation(const tl_object_ptr<td_api::Input
|
||||
}
|
||||
|
||||
FileId file_id = r_file_id.ok();
|
||||
auto it = std::find(saved_animation_ids_.begin(), saved_animation_ids_.end(), file_id);
|
||||
if (it == saved_animation_ids_.end()) {
|
||||
if (!td::remove(saved_animation_ids_, file_id)) {
|
||||
return promise.set_value(Unit());
|
||||
}
|
||||
|
||||
@ -766,8 +765,6 @@ void AnimationsManager::remove_saved_animation(const tl_object_ptr<td_api::Input
|
||||
|
||||
send_save_gif_query(file_id, true, std::move(promise));
|
||||
|
||||
saved_animation_ids_.erase(it);
|
||||
|
||||
send_update_saved_animations();
|
||||
}
|
||||
|
||||
|
@ -627,8 +627,7 @@ void BackgroundManager::on_installed_background(BackgroundId background_id, Back
|
||||
return promise.set_error(result.move_as_error());
|
||||
}
|
||||
|
||||
auto it = std::find(installed_background_ids_.begin(), installed_background_ids_.end(), background_id);
|
||||
if (it == installed_background_ids_.end()) {
|
||||
if (!td::contains(installed_background_ids_, background_id)) {
|
||||
installed_background_ids_.insert(installed_background_ids_.begin(), background_id);
|
||||
}
|
||||
set_background_id(background_id, type, for_dark_theme);
|
||||
@ -769,10 +768,7 @@ void BackgroundManager::on_removed_background(BackgroundId background_id, Result
|
||||
if (result.is_error()) {
|
||||
return promise.set_error(result.move_as_error());
|
||||
}
|
||||
auto it = std::find(installed_background_ids_.begin(), installed_background_ids_.end(), background_id);
|
||||
if (it != installed_background_ids_.end()) {
|
||||
installed_background_ids_.erase(it);
|
||||
}
|
||||
td::remove(installed_background_ids_, background_id);
|
||||
if (background_id == set_background_id_[0]) {
|
||||
set_background_id(BackgroundId(), BackgroundType(), false);
|
||||
}
|
||||
@ -1020,8 +1016,7 @@ td_api::object_ptr<td_api::backgrounds> BackgroundManager::get_backgrounds_objec
|
||||
return get_background_object(background_id, for_dark_theme);
|
||||
});
|
||||
auto background_id = set_background_id_[for_dark_theme];
|
||||
if (background_id.is_valid() && std::find(installed_background_ids_.begin(), installed_background_ids_.end(),
|
||||
background_id) == installed_background_ids_.end()) {
|
||||
if (background_id.is_valid() && !td::contains(installed_background_ids_, background_id)) {
|
||||
backgrounds.push_back(get_background_object(background_id, for_dark_theme));
|
||||
}
|
||||
std::stable_sort(backgrounds.begin(), backgrounds.end(),
|
||||
|
@ -5822,18 +5822,15 @@ void ContactsManager::update_dialogs_for_discussion(DialogId dialog_id, bool is_
|
||||
return;
|
||||
}
|
||||
|
||||
auto it = std::find(dialogs_for_discussion_.begin(), dialogs_for_discussion_.end(), dialog_id);
|
||||
bool is_found = it != dialogs_for_discussion_.end();
|
||||
if (is_suitable == is_found) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_suitable) {
|
||||
if (!td::contains(dialogs_for_discussion_, dialog_id)) {
|
||||
LOG(DEBUG) << "Add " << dialog_id << " to list of suitable discussion chats";
|
||||
dialogs_for_discussion_.insert(dialogs_for_discussion_.begin(), dialog_id);
|
||||
}
|
||||
} else {
|
||||
if (td::remove(dialogs_for_discussion_, dialog_id)) {
|
||||
LOG(DEBUG) << "Remove " << dialog_id << " from list of suitable discussion chats";
|
||||
dialogs_for_discussion_.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -7743,8 +7740,7 @@ void ContactsManager::update_channel(Channel *c, ChannelId channel_id, bool from
|
||||
if (c->username.empty()) {
|
||||
td::remove(created_public_channels_, channel_id);
|
||||
} else {
|
||||
if (std::find(created_public_channels_.begin(), created_public_channels_.end(), channel_id) ==
|
||||
created_public_channels_.end()) {
|
||||
if (!td::contains(created_public_channels_, channel_id)) {
|
||||
created_public_channels_.push_back(channel_id);
|
||||
}
|
||||
}
|
||||
@ -9241,9 +9237,7 @@ void ContactsManager::speculative_add_channel_participants(ChannelId channel_id,
|
||||
}
|
||||
}
|
||||
|
||||
if (channel_full != nullptr && is_user_bot(user_id) &&
|
||||
std::find(channel_full->bot_user_ids.begin(), channel_full->bot_user_ids.end(), user_id) ==
|
||||
channel_full->bot_user_ids.end()) {
|
||||
if (channel_full != nullptr && is_user_bot(user_id) && !td::contains(channel_full->bot_user_ids, user_id)) {
|
||||
channel_full->bot_user_ids.push_back(user_id);
|
||||
channel_full->need_save_to_database = true;
|
||||
}
|
||||
@ -9280,15 +9274,11 @@ void ContactsManager::speculative_delete_channel_participant(ChannelId channel_i
|
||||
|
||||
if (is_user_bot(deleted_user_id)) {
|
||||
auto channel_full = get_channel_full_force(channel_id);
|
||||
if (channel_full != nullptr) {
|
||||
auto user_it = std::find(channel_full->bot_user_ids.begin(), channel_full->bot_user_ids.end(), deleted_user_id);
|
||||
if (user_it != channel_full->bot_user_ids.end()) {
|
||||
channel_full->bot_user_ids.erase(user_it);
|
||||
if (channel_full != nullptr && td::remove(channel_full->bot_user_ids, deleted_user_id)) {
|
||||
channel_full->need_save_to_database = true;
|
||||
update_channel_full(channel_full, channel_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
speculative_add_channel_participants(channel_id, -1, by_me);
|
||||
}
|
||||
@ -9332,17 +9322,16 @@ void ContactsManager::speculative_add_channel_user(ChannelId channel_id, UserId
|
||||
auto administrators_it = dialog_administrators_.find(dialog_id);
|
||||
if (administrators_it != dialog_administrators_.end()) {
|
||||
auto user_ids = administrators_it->second;
|
||||
auto it = std::find(user_ids.begin(), user_ids.end(), user_id);
|
||||
bool is_found = it != user_ids.end();
|
||||
|
||||
if (new_status.is_administrator() != is_found) {
|
||||
if (is_found) {
|
||||
user_ids.erase(it);
|
||||
} else {
|
||||
if (new_status.is_administrator()) {
|
||||
if (!td::contains(user_ids, user_id)) {
|
||||
user_ids.push_back(user_id);
|
||||
}
|
||||
on_update_dialog_administrators(dialog_id, std::move(user_ids), true);
|
||||
}
|
||||
} else {
|
||||
if (td::remove(user_ids, user_id)) {
|
||||
on_update_dialog_administrators(dialog_id, std::move(user_ids), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -9384,15 +9373,12 @@ void ContactsManager::speculative_add_channel_user(ChannelId channel_id, UserId
|
||||
|
||||
if (new_status.is_member() != old_status.is_member() && is_user_bot(user_id)) {
|
||||
if (new_status.is_member()) {
|
||||
if (std::find(channel_full->bot_user_ids.begin(), channel_full->bot_user_ids.end(), user_id) ==
|
||||
channel_full->bot_user_ids.end()) {
|
||||
if (!td::contains(channel_full->bot_user_ids, user_id)) {
|
||||
channel_full->bot_user_ids.push_back(user_id);
|
||||
channel_full->need_save_to_database = true;
|
||||
}
|
||||
} else {
|
||||
auto user_it = std::find(channel_full->bot_user_ids.begin(), channel_full->bot_user_ids.end(), user_id);
|
||||
if (user_it != channel_full->bot_user_ids.end()) {
|
||||
channel_full->bot_user_ids.erase(user_it);
|
||||
if (td::remove(channel_full->bot_user_ids, user_id)) {
|
||||
channel_full->need_save_to_database = true;
|
||||
}
|
||||
}
|
||||
|
@ -1713,12 +1713,10 @@ bool InlineQueriesManager::update_bot_usage(UserId bot_user_id) {
|
||||
}
|
||||
|
||||
void InlineQueriesManager::remove_recent_inline_bot(UserId bot_user_id, Promise<Unit> &&promise) {
|
||||
auto it = std::find(recently_used_bot_user_ids_.begin(), recently_used_bot_user_ids_.end(), bot_user_id);
|
||||
if (it != recently_used_bot_user_ids_.end()) {
|
||||
recently_used_bot_user_ids_.erase(it);
|
||||
if (td::remove(recently_used_bot_user_ids_, bot_user_id)) {
|
||||
save_recently_used_bots();
|
||||
}
|
||||
return promise.set_value(Unit());
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -4849,7 +4849,7 @@ bool need_delay_message_content_notification(const MessageContent *content, User
|
||||
return true;
|
||||
case MessageContentType::ChatAddUsers: {
|
||||
auto &added_user_ids = static_cast<const MessageChatAddUsers *>(content)->user_ids;
|
||||
return std::find(added_user_ids.begin(), added_user_ids.end(), my_user_id) == added_user_ids.end();
|
||||
return !td::contains(added_user_ids, my_user_id);
|
||||
}
|
||||
case MessageContentType::ChatDeleteUser:
|
||||
return static_cast<const MessageChatDeleteUser *>(content)->user_id != my_user_id;
|
||||
|
@ -11394,7 +11394,7 @@ void MessagesManager::on_get_dialogs(FolderId folder_id, vector<tl_object_ptr<te
|
||||
}
|
||||
|
||||
DialogId dialog_id(dialog->peer_);
|
||||
if (std::find(added_dialog_ids.begin(), added_dialog_ids.end(), dialog_id) != added_dialog_ids.end()) {
|
||||
if (td::contains(added_dialog_ids, dialog_id)) {
|
||||
LOG(ERROR) << "Receive " << dialog_id << " twice in result of getChats with total_count = " << total_count;
|
||||
continue;
|
||||
}
|
||||
@ -12729,7 +12729,7 @@ void MessagesManager::on_get_common_dialogs(UserId user_id, int32 offset_chat_id
|
||||
CHECK(dialog_id.is_valid());
|
||||
td_->contacts_manager_->on_get_chat(std::move(chat), "on_get_common_dialogs");
|
||||
|
||||
if (std::find(result.begin(), result.end(), dialog_id) == result.end()) {
|
||||
if (!td::contains(result, dialog_id)) {
|
||||
force_create_dialog(dialog_id, "get common dialogs");
|
||||
result.push_back(dialog_id);
|
||||
}
|
||||
@ -13169,7 +13169,7 @@ Result<MessagesManager::MessageLinkInfo> MessagesManager::get_message_link_info(
|
||||
if (begins_with(cur_t_me_url, "http://") || begins_with(cur_t_me_url, "https://")) {
|
||||
Slice t_me_url = cur_t_me_url;
|
||||
t_me_url = t_me_url.substr(url[4] == 's' ? 8 : 7);
|
||||
if (std::find(t_me_urls.begin(), t_me_urls.end(), t_me_url) == t_me_urls.end()) {
|
||||
if (!td::contains(t_me_urls, t_me_url)) {
|
||||
t_me_urls.push_back(t_me_url);
|
||||
}
|
||||
}
|
||||
@ -22200,8 +22200,7 @@ void MessagesManager::on_dialog_bots_updated(DialogId dialog_id, vector<UserId>
|
||||
return;
|
||||
}
|
||||
const Message *m = get_message_force(d, d->reply_markup_message_id, "on_dialog_bots_updated");
|
||||
if (m == nullptr || (m->sender_user_id.is_valid() &&
|
||||
std::find(bot_user_ids.begin(), bot_user_ids.end(), m->sender_user_id) == bot_user_ids.end())) {
|
||||
if (m == nullptr || (m->sender_user_id.is_valid() && !td::contains(bot_user_ids, m->sender_user_id))) {
|
||||
LOG(INFO) << "Remove reply markup in " << dialog_id << ", because bot "
|
||||
<< (m == nullptr ? UserId() : m->sender_user_id) << " isn't a member of the chat";
|
||||
set_dialog_reply_markup(d, MessageId());
|
||||
@ -24373,8 +24372,7 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
|
||||
if (need_delete_message_files(d, m)) {
|
||||
FullMessageId full_message_id{dialog_id, message_id};
|
||||
for (auto file_id : old_file_ids) {
|
||||
if (std::find(new_file_ids.begin(), new_file_ids.end(), file_id) == new_file_ids.end() &&
|
||||
need_delete_file(full_message_id, file_id)) {
|
||||
if (!td::contains(new_file_ids, file_id) && need_delete_file(full_message_id, file_id)) {
|
||||
send_closure(G()->file_manager(), &FileManager::delete_file, file_id, Promise<>(),
|
||||
"edit message in add_message_to_dialog");
|
||||
}
|
||||
@ -28103,13 +28101,7 @@ bool MessagesManager::add_recently_found_dialog_internal(DialogId dialog_id) {
|
||||
|
||||
bool MessagesManager::remove_recently_found_dialog_internal(DialogId dialog_id) {
|
||||
CHECK(have_dialog(dialog_id));
|
||||
|
||||
auto it = std::find(recently_found_dialog_ids_.begin(), recently_found_dialog_ids_.end(), dialog_id);
|
||||
if (it == recently_found_dialog_ids_.end()) {
|
||||
return false;
|
||||
}
|
||||
recently_found_dialog_ids_.erase(it);
|
||||
return true;
|
||||
return td::remove(recently_found_dialog_ids_, dialog_id);
|
||||
}
|
||||
|
||||
void MessagesManager::suffix_load_loop(Dialog *d) {
|
||||
|
@ -392,8 +392,7 @@ NotificationManager::NotificationGroups::iterator NotificationManager::get_group
|
||||
return group_it;
|
||||
}
|
||||
|
||||
if (std::find(call_notification_group_ids_.begin(), call_notification_group_ids_.end(), group_id) !=
|
||||
call_notification_group_ids_.end()) {
|
||||
if (td::contains(call_notification_group_ids_, group_id)) {
|
||||
return groups_.end();
|
||||
}
|
||||
|
||||
@ -1263,7 +1262,7 @@ void NotificationManager::flush_pending_updates(int32 group_id, const char *sour
|
||||
auto has_common_notifications = [](const vector<td_api::object_ptr<td_api::notification>> ¬ifications,
|
||||
const vector<int32> ¬ification_ids) {
|
||||
for (auto ¬ification : notifications) {
|
||||
if (std::find(notification_ids.begin(), notification_ids.end(), notification->id_) != notification_ids.end()) {
|
||||
if (td::contains(notification_ids, notification->id_)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -429,8 +429,7 @@ td_api::object_ptr<td_api::poll> PollManager::get_poll_object(PollId poll_id, co
|
||||
} else {
|
||||
auto &chosen_options = it->second.options_;
|
||||
for (auto &poll_option : poll->options) {
|
||||
auto is_being_chosen =
|
||||
std::find(chosen_options.begin(), chosen_options.end(), poll_option.data) != chosen_options.end();
|
||||
auto is_being_chosen = td::contains(chosen_options, poll_option.data);
|
||||
if (poll_option.is_chosen) {
|
||||
voter_count_diff = -1;
|
||||
}
|
||||
|
@ -1856,7 +1856,7 @@ StickerSetId StickersManager::on_get_sticker_set_covered(tl_object_ptr<telegram_
|
||||
auto &sticker_ids = sticker_set->sticker_ids;
|
||||
|
||||
auto sticker_id = on_get_sticker_document(std::move(covered_set->cover_)).second;
|
||||
if (sticker_id.is_valid() && std::find(sticker_ids.begin(), sticker_ids.end(), sticker_id) == sticker_ids.end()) {
|
||||
if (sticker_id.is_valid() && !td::contains(sticker_ids, sticker_id)) {
|
||||
sticker_ids.push_back(sticker_id);
|
||||
sticker_set->is_changed = true;
|
||||
}
|
||||
@ -1880,8 +1880,7 @@ StickerSetId StickersManager::on_get_sticker_set_covered(tl_object_ptr<telegram_
|
||||
|
||||
for (auto &cover : multicovered_set->covers_) {
|
||||
auto sticker_id = on_get_sticker_document(std::move(cover)).second;
|
||||
if (sticker_id.is_valid() &&
|
||||
std::find(sticker_ids.begin(), sticker_ids.end(), sticker_id) == sticker_ids.end()) {
|
||||
if (sticker_id.is_valid() && !td::contains(sticker_ids, sticker_id)) {
|
||||
sticker_ids.push_back(sticker_id);
|
||||
sticker_set->is_changed = true;
|
||||
}
|
||||
@ -1967,7 +1966,7 @@ void StickersManager::on_get_messages_sticker_set(StickerSetId sticker_set_id,
|
||||
}
|
||||
auto &sticker_ids = s->emoji_stickers_map_[remove_emoji_modifiers(pack->emoticon_)];
|
||||
for (auto sticker_id : stickers) {
|
||||
if (std::find(sticker_ids.begin(), sticker_ids.end(), sticker_id) == sticker_ids.end()) {
|
||||
if (!td::contains(sticker_ids, sticker_id)) {
|
||||
sticker_ids.push_back(sticker_id);
|
||||
}
|
||||
}
|
||||
@ -2165,7 +2164,7 @@ vector<FileId> StickersManager::get_stickers(string emoji, int32 limit, bool for
|
||||
prepend_sticker_ids.reserve(favorite_sticker_ids_.size() + recent_sticker_ids_[0].size());
|
||||
append(prepend_sticker_ids, recent_sticker_ids_[0]);
|
||||
for (auto sticker_id : favorite_sticker_ids_) {
|
||||
if (std::find(prepend_sticker_ids.begin(), prepend_sticker_ids.end(), sticker_id) == prepend_sticker_ids.end()) {
|
||||
if (!td::contains(prepend_sticker_ids, sticker_id)) {
|
||||
prepend_sticker_ids.push_back(sticker_id);
|
||||
}
|
||||
}
|
||||
@ -2184,8 +2183,7 @@ vector<FileId> StickersManager::get_stickers(string emoji, int32 limit, bool for
|
||||
for (const auto &sticker_id : prepend_sticker_ids) {
|
||||
const Sticker *s = get_sticker(sticker_id);
|
||||
LOG(INFO) << "Have prepend sticker " << sticker_id << " from " << s->set_id;
|
||||
if (s->set_id.is_valid() &&
|
||||
std::find(sets_to_load.begin(), sets_to_load.end(), s->set_id) == sets_to_load.end()) {
|
||||
if (s->set_id.is_valid() && !td::contains(sets_to_load, s->set_id)) {
|
||||
const StickerSet *sticker_set = get_sticker_set(s->set_id);
|
||||
if (sticker_set == nullptr || !sticker_set->is_loaded) {
|
||||
sets_to_load.push_back(s->set_id);
|
||||
@ -2235,8 +2233,7 @@ vector<FileId> StickersManager::get_stickers(string emoji, int32 limit, bool for
|
||||
continue;
|
||||
}
|
||||
|
||||
if (std::find(examined_sticker_sets.begin(), examined_sticker_sets.end(), sticker_set) ==
|
||||
examined_sticker_sets.end()) {
|
||||
if (!td::contains(examined_sticker_sets, sticker_set)) {
|
||||
examined_sticker_sets.push_back(sticker_set);
|
||||
}
|
||||
}
|
||||
@ -2279,7 +2276,7 @@ vector<FileId> StickersManager::get_stickers(string emoji, int32 limit, bool for
|
||||
if (sticker_set != nullptr && sticker_set->was_loaded) {
|
||||
auto map_it = sticker_set->emoji_stickers_map_.find(emoji);
|
||||
if (map_it != sticker_set->emoji_stickers_map_.end()) {
|
||||
if (std::find(map_it->second.begin(), map_it->second.end(), sticker_id) != map_it->second.end()) {
|
||||
if (td::contains(map_it->second, sticker_id)) {
|
||||
LOG(INFO) << "Found prepend sticker " << sticker_id << " has matching emoji";
|
||||
is_good = true;
|
||||
}
|
||||
@ -2652,7 +2649,7 @@ void StickersManager::on_update_sticker_set(StickerSet *sticker_set, bool is_ins
|
||||
}
|
||||
|
||||
if (is_archived) {
|
||||
if (std::find(sticker_set_ids.begin(), sticker_set_ids.end(), sticker_set->id) == sticker_set_ids.end()) {
|
||||
if (!td::contains(sticker_set_ids, sticker_set->id)) {
|
||||
total_count++;
|
||||
sticker_set_ids.insert(sticker_set_ids.begin(), sticker_set->id);
|
||||
}
|
||||
@ -3108,7 +3105,7 @@ void StickersManager::on_get_archived_sticker_sets(
|
||||
CHECK(sticker_set != nullptr);
|
||||
update_sticker_set(sticker_set);
|
||||
|
||||
if (std::find(sticker_set_ids.begin(), sticker_set_ids.end(), sticker_set_id) == sticker_set_ids.end()) {
|
||||
if (!td::contains(sticker_set_ids, sticker_set_id)) {
|
||||
sticker_set_ids.push_back(sticker_set_id);
|
||||
}
|
||||
}
|
||||
@ -4267,8 +4264,7 @@ void StickersManager::remove_recent_sticker(bool is_attached, const tl_object_pt
|
||||
|
||||
vector<FileId> &sticker_ids = recent_sticker_ids_[is_attached];
|
||||
FileId file_id = r_file_id.ok();
|
||||
auto it = std::find(sticker_ids.begin(), sticker_ids.end(), file_id);
|
||||
if (it == sticker_ids.end()) {
|
||||
if (!td::remove(sticker_ids, file_id)) {
|
||||
return promise.set_value(Unit());
|
||||
}
|
||||
|
||||
@ -4279,8 +4275,6 @@ void StickersManager::remove_recent_sticker(bool is_attached, const tl_object_pt
|
||||
|
||||
send_save_recent_sticker_query(is_attached, file_id, true, std::move(promise));
|
||||
|
||||
sticker_ids.erase(it);
|
||||
|
||||
need_update_recent_stickers_[is_attached] = true;
|
||||
send_update_recent_stickers();
|
||||
}
|
||||
@ -4675,8 +4669,7 @@ void StickersManager::remove_favorite_sticker(const tl_object_ptr<td_api::InputF
|
||||
}
|
||||
|
||||
FileId file_id = r_file_id.ok();
|
||||
auto it = std::find(favorite_sticker_ids_.begin(), favorite_sticker_ids_.end(), file_id);
|
||||
if (it == favorite_sticker_ids_.end()) {
|
||||
if (!td::remove(favorite_sticker_ids_, file_id)) {
|
||||
return promise.set_value(Unit());
|
||||
}
|
||||
|
||||
@ -4687,8 +4680,6 @@ void StickersManager::remove_favorite_sticker(const tl_object_ptr<td_api::InputF
|
||||
|
||||
send_fave_sticker_query(file_id, true, std::move(promise));
|
||||
|
||||
favorite_sticker_ids_.erase(it);
|
||||
|
||||
send_update_favorite_stickers();
|
||||
}
|
||||
|
||||
@ -5075,7 +5066,7 @@ void StickersManager::on_get_emoji_keywords_difference(
|
||||
vector<string> emojis = search_language_emojis(language_code, text, true);
|
||||
bool is_changed = false;
|
||||
for (auto &emoji : keyword->emoticons_) {
|
||||
if (std::find(emojis.begin(), emojis.end(), emoji) == emojis.end()) {
|
||||
if (!td::contains(emojis, emoji)) {
|
||||
emojis.push_back(emoji);
|
||||
is_changed = true;
|
||||
}
|
||||
@ -5095,9 +5086,7 @@ void StickersManager::on_get_emoji_keywords_difference(
|
||||
vector<string> emojis = search_language_emojis(language_code, text, true);
|
||||
bool is_changed = false;
|
||||
for (auto &emoji : keyword->emoticons_) {
|
||||
auto it = std::find(emojis.begin(), emojis.end(), emoji);
|
||||
if (it != emojis.end()) {
|
||||
emojis.erase(it);
|
||||
if (td::remove(emojis, emoji)) {
|
||||
is_changed = true;
|
||||
}
|
||||
}
|
||||
|
@ -103,15 +103,12 @@ void FileGcWorker::run_gc(const FileGcParameters ¶meters, std::vector<FullFi
|
||||
new_stats.add(FullFileInfo(info));
|
||||
return true;
|
||||
}
|
||||
if (std::find(parameters.exclude_owner_dialog_ids.begin(), parameters.exclude_owner_dialog_ids.end(),
|
||||
info.owner_dialog_id) != parameters.exclude_owner_dialog_ids.end()) {
|
||||
if (td::contains(parameters.exclude_owner_dialog_ids, info.owner_dialog_id)) {
|
||||
exclude_owner_dialog_id_ignored_cnt++;
|
||||
new_stats.add(FullFileInfo(info));
|
||||
return true;
|
||||
}
|
||||
if (!parameters.owner_dialog_ids.empty() &&
|
||||
std::find(parameters.owner_dialog_ids.begin(), parameters.owner_dialog_ids.end(), info.owner_dialog_id) ==
|
||||
parameters.owner_dialog_ids.end()) {
|
||||
if (!parameters.owner_dialog_ids.empty() && !td::contains(parameters.owner_dialog_ids, info.owner_dialog_id)) {
|
||||
owner_dialog_id_ignored_cnt++;
|
||||
new_stats.add(FullFileInfo(info));
|
||||
return true;
|
||||
|
@ -971,9 +971,8 @@ void FileManager::try_forget_file_id(FileId file_id) {
|
||||
}
|
||||
|
||||
LOG(DEBUG) << "Forget file " << file_id;
|
||||
auto it = std::find(file_node->file_ids_.begin(), file_node->file_ids_.end(), file_id);
|
||||
CHECK(it != file_node->file_ids_.end());
|
||||
file_node->file_ids_.erase(it);
|
||||
bool is_removed = td::remove(file_node->file_ids_, file_id);
|
||||
CHECK(is_removed);
|
||||
*info = FileIdInfo();
|
||||
empty_file_ids_.push_back(file_id.get());
|
||||
}
|
||||
@ -1038,7 +1037,7 @@ Result<FileId> FileManager::register_generate(FileType file_type, FileLocationSo
|
||||
// add #mtime# into conversion
|
||||
if (!original_path.empty() && conversion[0] != '#' && PathView(original_path).is_absolute()) {
|
||||
auto file_paths = log_interface->get_file_paths();
|
||||
if (std::find(file_paths.begin(), file_paths.end(), original_path) == file_paths.end()) {
|
||||
if (!td::contains(file_paths, original_path)) {
|
||||
auto r_stat = stat(original_path);
|
||||
uint64 mtime = r_stat.is_ok() ? r_stat.ok().mtime_nsec_ : 0;
|
||||
conversion = PSTRING() << "#mtime#" << lpad0(to_string(mtime), 20) << '#' << conversion;
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
namespace td {
|
||||
namespace detail {
|
||||
|
||||
void BinlogEventsBuffer::add_event(BinlogEvent &&event) {
|
||||
total_events_++;
|
||||
if ((event.flags_ & BinlogEvent::Flags::Partial) == 0) {
|
||||
@ -26,14 +27,17 @@ void BinlogEventsBuffer::add_event(BinlogEvent &&event) {
|
||||
size_ += event.size_;
|
||||
events_.push_back(std::move(event));
|
||||
}
|
||||
|
||||
bool BinlogEventsBuffer::need_flush() const {
|
||||
return total_events_ > 5000 || ids_.size() > 100;
|
||||
}
|
||||
|
||||
void BinlogEventsBuffer::clear() {
|
||||
ids_.clear();
|
||||
events_.clear();
|
||||
total_events_ = 0;
|
||||
size_ = 0;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace td
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
namespace td {
|
||||
namespace detail {
|
||||
|
||||
class BinlogEventsBuffer {
|
||||
public:
|
||||
void add_event(BinlogEvent &&event);
|
||||
@ -45,5 +46,6 @@ class BinlogEventsBuffer {
|
||||
void do_event(BinlogEvent &&event);
|
||||
void clear();
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace td
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
namespace td {
|
||||
namespace detail {
|
||||
|
||||
class BinlogEventsProcessor {
|
||||
public:
|
||||
Status add_event(BinlogEvent &&event) TD_WARN_UNUSED_RESULT {
|
||||
@ -54,5 +55,6 @@ class BinlogEventsProcessor {
|
||||
Status do_event(BinlogEvent &&event);
|
||||
void compactify();
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace td
|
||||
|
@ -68,7 +68,7 @@ vector<string> Hints::get_words(Slice name, bool is_search) {
|
||||
|
||||
void Hints::add_word(const string &word, KeyT key, std::map<string, vector<KeyT>> &word_to_keys) {
|
||||
vector<KeyT> &keys = word_to_keys[word];
|
||||
CHECK(std::find(keys.begin(), keys.end(), key) == keys.end());
|
||||
CHECK(!td::contains(keys, key));
|
||||
keys.push_back(key);
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "td/telegram/SetWithPosition.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/misc.h"
|
||||
#include "td/utils/Random.h"
|
||||
#include "td/utils/tests.h"
|
||||
|
||||
@ -21,8 +22,7 @@ template <class T>
|
||||
class OldSetWithPosition {
|
||||
public:
|
||||
void add(T value) {
|
||||
auto it = std::find(values_.begin(), values_.end(), value);
|
||||
if (it != values_.end()) {
|
||||
if (td::contains(values_, value)) {
|
||||
return;
|
||||
}
|
||||
values_.push_back(value);
|
||||
|
Reference in New Issue
Block a user