From 192fd4862fc2fd3f65c6d3107408e65d1177efba Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 30 Dec 2020 18:50:57 +0300 Subject: [PATCH] Use td::unique. --- td/telegram/ConfigManager.cpp | 3 +-- td/telegram/NotificationManager.cpp | 5 +---- td/telegram/PollManager.cpp | 3 +-- td/telegram/PrivacyManager.cpp | 3 +-- td/telegram/SetWithPosition.h | 3 +-- td/telegram/StickersManager.cpp | 9 +++------ td/telegram/files/FileManager.cpp | 3 +-- tdutils/td/utils/Hints.cpp | 3 +-- tdutils/td/utils/translit.cpp | 3 +-- tdutils/test/port.cpp | 5 +++-- 10 files changed, 14 insertions(+), 26 deletions(-) diff --git a/td/telegram/ConfigManager.cpp b/td/telegram/ConfigManager.cpp index 5b331bcaf..efb1a84b4 100644 --- a/td/telegram/ConfigManager.cpp +++ b/td/telegram/ConfigManager.cpp @@ -1699,8 +1699,7 @@ void ConfigManager::process_app_config(tl_object_ptr &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 added_actions; vector removed_actions; diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index 2cb7ad874..fef33705a 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -1253,10 +1253,7 @@ void NotificationManager::flush_pending_updates(int32 group_id, const char *sour auto update_ptr = static_cast(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()); } diff --git a/td/telegram/PollManager.cpp b/td/telegram/PollManager.cpp index 2385c5b0e..98159e78e 100644 --- a/td/telegram/PollManager.cpp +++ b/td/telegram/PollManager.cpp @@ -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 &&option_ids, Promise &&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")); diff --git a/td/telegram/PrivacyManager.cpp b/td/telegram/PrivacyManager.cpp index 9d856ef12..b2f5f3efc 100644 --- a/td/telegram/PrivacyManager.cpp +++ b/td/telegram/PrivacyManager.cpp @@ -410,8 +410,7 @@ vector 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; } diff --git a/td/telegram/SetWithPosition.h b/td/telegram/SetWithPosition.h index 526f8eea3..9831b5fce 100644 --- a/td/telegram/SetWithPosition.h +++ b/td/telegram/SetWithPosition.h @@ -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); } diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 148b90675..e405b4e0b 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -6154,8 +6154,7 @@ void StickersManager::on_get_language_codes(const string &key, Result StickersManager::get_emoji_language_codes(const vector &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 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; diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 184acb913..2d36a09c2 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -1231,8 +1231,7 @@ Result 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) { diff --git a/tdutils/td/utils/Hints.cpp b/tdutils/td/utils/Hints.cpp index e0996aeb0..d3213f148 100644 --- a/tdutils/td/utils/Hints.cpp +++ b/tdutils/td/utils/Hints.cpp @@ -153,8 +153,7 @@ vector 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; } diff --git a/tdutils/td/utils/translit.cpp b/tdutils/td/utils/translit.cpp index 2b14f0364..7ae9c3250 100644 --- a/tdutils/td/utils/translit.cpp +++ b/tdutils/td/utils/translit.cpp @@ -107,8 +107,7 @@ vector 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; } diff --git a/tdutils/test/port.cpp b/tdutils/test/port.cpp index 9238dd826..5519167d0 100644 --- a/tdutils/test/port.cpp +++ b/tdutils/test/port.cpp @@ -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; } }