Use const reference if range-based for if appropriate.

This commit is contained in:
levlam 2021-11-10 20:39:35 +03:00
parent 2392cc7631
commit 5a02af8c72
11 changed files with 39 additions and 38 deletions

View File

@ -273,27 +273,27 @@ unique_ptr<DialogFilter> DialogFilter::merge_dialog_filter_changes(const DialogF
// merge additions and deletions from other clients to the local changes
std::unordered_set<DialogId, DialogIdHash> deleted_dialog_ids;
for (auto old_dialog_id : old_server_dialog_ids) {
for (const auto &old_dialog_id : old_server_dialog_ids) {
deleted_dialog_ids.insert(old_dialog_id.get_dialog_id());
}
std::unordered_set<DialogId, DialogIdHash> added_dialog_ids;
for (auto new_dialog_id : new_server_dialog_ids) {
for (const auto &new_dialog_id : new_server_dialog_ids) {
auto dialog_id = new_dialog_id.get_dialog_id();
if (deleted_dialog_ids.erase(dialog_id) == 0) {
added_dialog_ids.insert(dialog_id);
}
}
vector<InputDialogId> result;
for (auto input_dialog_id : new_dialog_ids) {
for (const auto &input_dialog_id : new_dialog_ids) {
// do not add dialog twice
added_dialog_ids.erase(input_dialog_id.get_dialog_id());
}
for (auto new_dialog_id : new_server_dialog_ids) {
for (const auto &new_dialog_id : new_server_dialog_ids) {
if (added_dialog_ids.count(new_dialog_id.get_dialog_id()) == 1) {
result.push_back(new_dialog_id);
}
}
for (auto input_dialog_id : new_dialog_ids) {
for (const auto &input_dialog_id : new_dialog_ids) {
if (deleted_dialog_ids.count(input_dialog_id.get_dialog_id()) == 0) {
result.push_back(input_dialog_id);
}

View File

@ -203,7 +203,7 @@ class CreateGroupCallQuery final : public Td::ResultHandler {
return on_error(Status::Error(500, "Receive wrong response"));
}
auto group_call_id = group_call_ids[0];
for (auto other_group_call_id : group_call_ids) {
for (const auto &other_group_call_id : group_call_ids) {
if (group_call_id != other_group_call_id) {
LOG(ERROR) << "Receive wrong CreateGroupCallQuery response " << to_string(ptr);
return on_error(Status::Error(500, "Receive wrong response"));
@ -2289,7 +2289,7 @@ void GroupCallManager::on_update_dialog_about(DialogId dialog_id, const string &
}
CHECK(!it->second.empty());
for (auto input_group_call_id : it->second) {
for (const auto &input_group_call_id : it->second) {
auto participant = get_group_call_participant(input_group_call_id, dialog_id);
CHECK(participant != nullptr);
if ((from_server || participant->is_fake) && participant->about != about) {

View File

@ -74,7 +74,7 @@ vector<telegram_api::object_ptr<telegram_api::InputDialogPeer>> InputDialogId::g
const vector<InputDialogId> &input_dialog_ids) {
vector<telegram_api::object_ptr<telegram_api::InputDialogPeer>> result;
result.reserve(input_dialog_ids.size());
for (auto input_dialog_id : input_dialog_ids) {
for (const auto &input_dialog_id : input_dialog_ids) {
auto input_peer = input_dialog_id.get_input_peer();
if (input_peer != nullptr) {
result.push_back(telegram_api::make_object<telegram_api::inputDialogPeer>(std::move(input_peer)));
@ -87,7 +87,7 @@ vector<telegram_api::object_ptr<telegram_api::InputPeer>> InputDialogId::get_inp
const vector<InputDialogId> &input_dialog_ids) {
vector<telegram_api::object_ptr<telegram_api::InputPeer>> result;
result.reserve(input_dialog_ids.size());
for (auto input_dialog_id : input_dialog_ids) {
for (const auto &input_dialog_id : input_dialog_ids) {
auto input_peer = input_dialog_id.get_input_peer();
CHECK(input_peer != nullptr);
result.push_back(std::move(input_peer));

View File

@ -6958,7 +6958,7 @@ void MessagesManager::on_update_some_live_location_viewed(Promise<Unit> &&promis
// update all live locations, because it is unknown, which exactly was viewed
auto active_live_location_message_ids = get_active_live_location_messages(Auto());
for (auto full_message_id : active_live_location_message_ids) {
for (const auto &full_message_id : active_live_location_message_ids) {
send_update_message_live_location_viewed(full_message_id);
}
@ -9176,7 +9176,7 @@ void MessagesManager::after_get_difference() {
break;
}
}
for (auto full_message_id : update_message_ids_to_delete) {
for (const auto &full_message_id : update_message_ids_to_delete) {
update_message_ids_.erase(full_message_id);
}
@ -10018,7 +10018,7 @@ void MessagesManager::on_get_scheduled_server_messages(DialogId dialog_id, uint3
}
on_update_dialog_has_scheduled_server_messages(dialog_id, has_scheduled_server_messages);
for (auto it : old_server_message_ids) {
for (const auto &it : old_server_message_ids) {
auto message_id = it.second;
auto message = do_delete_scheduled_message(d, message_id, true, "on_get_scheduled_server_messages");
CHECK(message != nullptr);
@ -15707,7 +15707,7 @@ void MessagesManager::load_dialog_filter(const DialogFilter *filter, bool force,
vector<InputDialogId> needed_dialog_ids;
for (auto input_dialog_ids :
{&filter->pinned_dialog_ids, &filter->excluded_dialog_ids, &filter->included_dialog_ids}) {
for (auto input_dialog_id : *input_dialog_ids) {
for (const auto &input_dialog_id : *input_dialog_ids) {
if (!have_dialog(input_dialog_id.get_dialog_id())) {
needed_dialog_ids.push_back(input_dialog_id);
}
@ -15715,7 +15715,7 @@ void MessagesManager::load_dialog_filter(const DialogFilter *filter, bool force,
}
vector<InputDialogId> input_dialog_ids;
for (auto &input_dialog_id : needed_dialog_ids) {
for (const auto &input_dialog_id : needed_dialog_ids) {
auto dialog_id = input_dialog_id.get_dialog_id();
// TODO load dialogs asynchronously
if (!have_dialog_force(dialog_id, "load_dialog_filter")) {
@ -18200,7 +18200,7 @@ void MessagesManager::sort_dialog_filter_input_dialog_ids(DialogFilter *dialog_f
std::unordered_set<DialogId, DialogIdHash> all_dialog_ids;
for (auto input_dialog_ids :
{&dialog_filter->pinned_dialog_ids, &dialog_filter->excluded_dialog_ids, &dialog_filter->included_dialog_ids}) {
for (auto input_dialog_id : *input_dialog_ids) {
for (const auto &input_dialog_id : *input_dialog_ids) {
LOG_CHECK(all_dialog_ids.insert(input_dialog_id.get_dialog_id()).second)
<< source << ' ' << input_dialog_id.get_dialog_id() << ' ' << dialog_filter;
}
@ -18211,7 +18211,7 @@ Result<unique_ptr<DialogFilter>> MessagesManager::create_dialog_filter(DialogFil
td_api::object_ptr<td_api::chatFilter> filter) {
CHECK(filter != nullptr);
for (auto chat_ids : {&filter->pinned_chat_ids_, &filter->excluded_chat_ids_, &filter->included_chat_ids_}) {
for (auto chat_id : *chat_ids) {
for (const auto &chat_id : *chat_ids) {
DialogId dialog_id(chat_id);
if (!dialog_id.is_valid()) {
return Status::Error(400, "Invalid chat identifier specified");
@ -18234,7 +18234,7 @@ Result<unique_ptr<DialogFilter>> MessagesManager::create_dialog_filter(DialogFil
std::unordered_set<int64> added_dialog_ids;
auto add_chats = [this, &added_dialog_ids](vector<InputDialogId> &input_dialog_ids, const vector<int64> &chat_ids) {
for (auto &chat_id : chat_ids) {
for (const auto &chat_id : chat_ids) {
if (!added_dialog_ids.insert(chat_id).second) {
// do not allow duplicate chat_ids
continue;
@ -18296,7 +18296,7 @@ void MessagesManager::create_dialog_filter(td_api::object_ptr<td_api::chatFilter
auto chat_filter_info = dialog_filter->get_chat_filter_info_object();
bool at_beginning = false;
for (auto &recommended_dialog_filter : recommended_dialog_filters_) {
for (const auto &recommended_dialog_filter : recommended_dialog_filters_) {
if (DialogFilter::are_similar(*recommended_dialog_filter.dialog_filter, *dialog_filter)) {
at_beginning = true;
}
@ -18744,7 +18744,7 @@ void MessagesManager::edit_dialog_filter(unique_ptr<DialogFilter> new_dialog_fil
save_unread_chat_count(old_list);
}
for (auto it : updated_position_dialogs) {
for (const auto &it : updated_position_dialogs) {
send_update_chat_position(dialog_list_id, it.second, source);
}
@ -21922,14 +21922,14 @@ void MessagesManager::on_load_active_live_location_full_message_ids_from_databas
// TODO asynchronously load messages from database
active_live_location_full_message_ids_.clear();
for (auto full_message_id : old_full_message_ids) {
for (const auto &full_message_id : old_full_message_ids) {
Message *m = get_message_force(full_message_id, "on_load_active_live_location_full_message_ids_from_database");
if (m != nullptr) {
try_add_active_live_location(full_message_id.get_dialog_id(), m);
}
}
for (auto full_message_id : new_full_message_ids) {
for (const auto &full_message_id : new_full_message_ids) {
add_active_live_location(full_message_id);
}
@ -22297,7 +22297,7 @@ td_api::object_ptr<td_api::foundMessages> MessagesManager::get_found_messages_ob
const FoundMessages &found_messages, const char *source) {
vector<tl_object_ptr<td_api::message>> result;
result.reserve(found_messages.full_message_ids.size());
for (auto full_message_id : found_messages.full_message_ids) {
for (const auto &full_message_id : found_messages.full_message_ids) {
auto message = get_message_object(full_message_id, source);
if (message != nullptr) {
result.push_back(std::move(message));
@ -33618,7 +33618,7 @@ bool MessagesManager::need_delete_file(FullMessageId full_message_id, FileId fil
auto full_message_ids = td_->file_reference_manager_->get_some_message_file_sources(main_file_id);
LOG(INFO) << "Receive " << full_message_ids << " as sources for file " << main_file_id << "/" << file_id << " from "
<< full_message_id;
for (auto other_full_messsage_id : full_message_ids) {
for (const auto &other_full_messsage_id : full_message_ids) {
if (other_full_messsage_id != full_message_id) {
return false;
}

View File

@ -1360,7 +1360,7 @@ void NotificationManager::flush_all_pending_updates(bool include_delayed_chats,
// flush groups in reverse order to not exceed max_notification_group_count_
VLOG(notifications) << "Flush pending updates in " << ready_group_keys.size() << " notification groups";
std::sort(ready_group_keys.begin(), ready_group_keys.end());
for (auto group_key : reversed(ready_group_keys)) {
for (const auto &group_key : reversed(ready_group_keys)) {
force_flush_pending_updates(group_key.group_id, "flush_all_pending_updates");
}
if (include_delayed_chats) {

View File

@ -321,7 +321,7 @@ void PollManager::notify_on_poll_update(PollId poll_id) {
return;
}
for (auto full_message_id : it->second) {
for (const auto &full_message_id : it->second) {
td_->messages_manager_->on_external_update_message_content(full_message_id);
}
}
@ -455,8 +455,9 @@ vector<int32> PollManager::get_vote_percentage(const vector<int32> &voter_counts
option.count++;
}
vector<Option> sorted_options;
for (auto option : options) {
auto pos = option.second.pos;
for (const auto &it : options) {
const auto &option = it.second;
auto pos = option.pos;
if (gap[pos] > total_voter_count / 2) {
// do not round to wrong direction
continue;
@ -465,7 +466,7 @@ vector<int32> PollManager::get_vote_percentage(const vector<int32> &voter_counts
// round halves to the 50%
continue;
}
sorted_options.push_back(option.second);
sorted_options.push_back(option);
}
std::sort(sorted_options.begin(), sorted_options.end(), [&](const Option &lhs, const Option &rhs) {
if (gap[lhs.pos] != gap[rhs.pos]) {

View File

@ -1078,7 +1078,7 @@ void SecureManager::on_get_passport_authorization_form_secret(int32 authorizatio
auto *file_manager = G()->td().get_actor_unsafe()->file_manager_.get();
std::vector<TdApiSecureValue> values;
std::map<SecureValueType, SecureValueCredentials> all_credentials;
for (auto suitable_type : it->second.options) {
for (const auto &suitable_type : it->second.options) {
auto type = suitable_type.first;
for (auto &value : it->second.values) {
if (value == nullptr) {

View File

@ -1442,11 +1442,11 @@ void StickersManager::on_load_special_sticker_set(const SpecialStickerSetType &t
}
vector<FullMessageId> full_message_ids;
for (auto full_message_id : it->second) {
for (const auto &full_message_id : it->second) {
full_message_ids.push_back(full_message_id);
}
CHECK(!full_message_ids.empty());
for (auto full_message_id : full_message_ids) {
for (const auto &full_message_id : full_message_ids) {
td_->messages_manager_->on_external_update_message_content(full_message_id);
}
}
@ -4175,12 +4175,12 @@ 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 (auto full_message_id : it.second.full_message_ids) {
for (const auto &full_message_id : it.second.full_message_ids) {
full_message_ids.push_back(full_message_id);
}
}
}
for (auto full_message_id : full_message_ids) {
for (const auto &full_message_id : full_message_ids) {
td_->messages_manager_->on_external_update_message_content(full_message_id);
}
}

View File

@ -1295,11 +1295,11 @@ void WebPagesManager::on_web_page_changed(WebPageId web_page_id, bool have_web_p
auto it = web_page_messages_.find(web_page_id);
if (it != web_page_messages_.end()) {
vector<FullMessageId> full_message_ids;
for (auto full_message_id : it->second) {
for (const auto &full_message_id : it->second) {
full_message_ids.push_back(full_message_id);
}
CHECK(!full_message_ids.empty());
for (auto full_message_id : full_message_ids) {
for (const auto &full_message_id : full_message_ids) {
if (!have_web_page) {
td_->messages_manager_->delete_pending_message_web_page(full_message_id);
} else {
@ -1354,7 +1354,7 @@ void WebPagesManager::on_pending_web_page_timeout(WebPageId web_page_id) {
auto it = web_page_messages_.find(web_page_id);
if (it != web_page_messages_.end()) {
vector<FullMessageId> full_message_ids;
for (auto full_message_id : it->second) {
for (const auto &full_message_id : it->second) {
if (full_message_id.get_dialog_id().get_type() != DialogType::SecretChat) {
full_message_ids.push_back(full_message_id);
}

View File

@ -175,7 +175,7 @@ class RangeSet {
vector<int32> as_vector(int32 part_size) const {
vector<int32> res;
for (auto it : ranges_) {
for (const auto &it : ranges_) {
auto begin = narrow_cast<int32>((it.begin + part_size - 1) / part_size);
auto end = narrow_cast<int32>(it.end / part_size);
while (begin < end) {

View File

@ -111,7 +111,7 @@ TEST(CryptoPQ, generated_slow) {
test_pq(2, 2);
}
auto queries = gen_pq_queries();
for (auto query : queries) {
for (const auto &query : queries) {
test_pq(query.first, query.second);
}
}