Use td::unique.

This commit is contained in:
levlam 2020-12-30 18:50:57 +03:00
parent 45149bb3cd
commit 192fd4862f
10 changed files with 14 additions and 26 deletions

View File

@ -1699,8 +1699,7 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
// do not update suggested actions while changing content settings or dismissing an action
if (!is_set_content_settings_request_sent_ && dismiss_suggested_action_request_count_ == 0) {
std::sort(suggested_actions.begin(), suggested_actions.end());
suggested_actions.erase(std::unique(suggested_actions.begin(), suggested_actions.end()), suggested_actions.end());
td::unique(suggested_actions);
if (suggested_actions != suggested_actions_) {
vector<SuggestedAction> added_actions;
vector<SuggestedAction> removed_actions;

View File

@ -1253,10 +1253,7 @@ void NotificationManager::flush_pending_updates(int32 group_id, const char *sour
auto update_ptr = static_cast<td_api::updateNotificationGroup *>(update.get());
append(update_ptr->removed_notification_ids_, std::move(moved_deleted_notification_ids));
auto old_size = update_ptr->removed_notification_ids_.size();
std::sort(update_ptr->removed_notification_ids_.begin(), update_ptr->removed_notification_ids_.end());
update_ptr->removed_notification_ids_.erase(
std::unique(update_ptr->removed_notification_ids_.begin(), update_ptr->removed_notification_ids_.end()),
update_ptr->removed_notification_ids_.end());
td::unique(update_ptr->removed_notification_ids_);
CHECK(old_size == update_ptr->removed_notification_ids_.size());
}

View File

@ -675,8 +675,7 @@ string PollManager::get_poll_search_text(PollId poll_id) const {
void PollManager::set_poll_answer(PollId poll_id, FullMessageId full_message_id, vector<int32> &&option_ids,
Promise<Unit> &&promise) {
std::sort(option_ids.begin(), option_ids.end());
option_ids.erase(std::unique(option_ids.begin(), option_ids.end()), option_ids.end());
td::unique(option_ids);
if (is_local_poll_id(poll_id)) {
return promise.set_error(Status::Error(400, "Poll can't be answered"));

View File

@ -410,8 +410,7 @@ vector<int32> PrivacyManager::UserPrivacySettingRules::get_restricted_user_ids()
for (auto &rule : rules_) {
combine(result, rule.get_restricted_user_ids());
}
std::sort(result.begin(), result.end());
result.erase(std::unique(result.begin(), result.end()), result.end());
td::unique(result);
return result;
}

View File

@ -29,8 +29,7 @@ class FastSetWithPosition {
res.push_back(*not_checked_.begin());
res.push_back(*not_checked_.rbegin());
}
std::sort(res.begin(), res.end());
res.erase(std::unique(res.begin(), res.end()), res.end());
td::unique(res);
if (res.size() > 2) {
res.erase(res.begin() + 1, res.end() - 1);
}

View File

@ -6154,8 +6154,7 @@ void StickersManager::on_get_language_codes(const string &key, Result<vector<str
LOG(ERROR) << "Language codes list is empty";
language_codes.emplace_back("en");
}
std::sort(language_codes.begin(), language_codes.end());
language_codes.erase(std::unique(language_codes.begin(), language_codes.end()), language_codes.end());
td::unique(language_codes);
auto it = emoji_language_codes_.find(key);
CHECK(it != emoji_language_codes_.end());
@ -6207,8 +6206,7 @@ vector<string> StickersManager::get_emoji_language_codes(const vector<string> &i
LOG(INFO) << "List of language codes is empty";
language_codes.push_back("en");
}
std::sort(language_codes.begin(), language_codes.end());
language_codes.erase(std::unique(language_codes.begin(), language_codes.end()), language_codes.end());
td::unique(language_codes);
LOG(DEBUG) << "Have language codes " << language_codes;
auto key = get_emoji_language_codes_database_key(language_codes);
@ -6474,8 +6472,7 @@ vector<string> StickersManager::search_emojis(const string &text, bool exact_mat
combine(result, search_language_emojis(language_code, text_lowered, exact_match));
}
std::sort(result.begin(), result.end());
result.erase(std::unique(result.begin(), result.end()), result.end());
td::unique(result);
promise.set_value(Unit());
return result;

View File

@ -1231,8 +1231,7 @@ Result<FileId> FileManager::register_file(FileData &&data, FileLocationSource fi
if (file_view.has_generate_location()) {
new_generate = register_location(file_view.generate_location(), generate_location_to_file_id_);
}
std::sort(to_merge.begin(), to_merge.end());
to_merge.erase(std::unique(to_merge.begin(), to_merge.end()), to_merge.end());
td::unique(to_merge);
int new_cnt = new_remote + new_local + new_generate;
if (data.pmc_id_ == 0 && file_db_ && new_cnt > 0) {

View File

@ -153,8 +153,7 @@ vector<Hints::KeyT> Hints::search_word(const string &word) const {
add_search_results(results, w, word_to_keys_);
}
std::sort(results.begin(), results.end());
results.erase(std::unique(results.begin(), results.end()), results.end());
td::unique(results);
return results;
}

View File

@ -107,8 +107,7 @@ vector<string> get_word_transliterations(Slice word, bool allow_partial) {
add_word_transliterations(result, word, allow_partial, get_en_to_ru_simple_rules(), get_en_to_ru_complex_rules());
add_word_transliterations(result, word, allow_partial, get_ru_to_en_simple_rules(), get_ru_to_en_complex_rules());
std::sort(result.begin(), result.end());
result.erase(std::unique(result.begin(), result.end()), result.end());
td::unique(result);
return result;
}

View File

@ -210,8 +210,9 @@ TEST(Port, SignalsAndThread) {
}
std::sort(ptrs.begin(), ptrs.end());
CHECK(ptrs == ans);
std::sort(addrs.begin(), addrs.end());
ASSERT_TRUE(std::unique(addrs.begin(), addrs.end()) == addrs.end());
auto addrs_size = addrs.size();
td::unique(addrs);
ASSERT_EQ(addrs_size, addrs.size());
//LOG(ERROR) << addrs;
}
}