From 9f44816a6211fdefc8261d7b8a3f670575ca6df7 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 21 Oct 2021 12:51:16 +0300 Subject: [PATCH] Minor improvements. --- benchmark/bench_tddb.cpp | 1 + td/generate/scheme/td_api.tl | 4 +- td/generate/tl_writer_jni_cpp.cpp | 8 +-- td/mtproto/Ping.h | 1 + td/mtproto/RawConnection.cpp | 5 +- td/telegram/CallbackQueriesManager.cpp | 1 - td/telegram/CallbackQueriesManager.h | 2 - td/telegram/ClientActor.cpp | 2 +- td/telegram/ConfigManager.h | 1 - td/telegram/ContactsManager.h | 6 +-- td/telegram/DelayDispatcher.cpp | 2 - td/telegram/DialogParticipant.cpp | 1 - td/telegram/DraftMessage.h | 1 + td/telegram/FileReferenceManager.cpp | 1 + td/telegram/GroupCallManager.cpp | 1 + td/telegram/MessageContent.cpp | 2 + td/telegram/MessageContent.h | 1 + td/telegram/MessagesDb.cpp | 6 ++- td/telegram/MessagesManager.cpp | 2 +- td/telegram/MessagesManager.h | 3 +- td/telegram/StickersManager.cpp | 2 +- td/telegram/StickersManager.h | 3 +- td/telegram/StorageManager.cpp | 1 + td/telegram/Td.cpp | 3 +- td/telegram/ThemeManager.cpp | 1 + td/telegram/TopDialogManager.cpp | 8 +-- td/telegram/TopDialogManager.h | 9 ++-- td/telegram/cli.cpp | 52 ++++++++++---------- td/telegram/files/FileDb.cpp | 2 +- td/telegram/files/FileGcWorker.cpp | 1 - td/telegram/files/FileStatsWorker.cpp | 1 - td/telegram/misc.h | 1 - td/telegram/net/NetStatsManager.h | 7 +-- td/telegram/td_emscripten.cpp | 2 +- tdactor/example/example.cpp | 2 +- tdactor/td/actor/PromiseFuture.h | 4 +- tdactor/test/actors_bugs.cpp | 2 +- tdactor/test/actors_main.cpp | 5 +- tdactor/test/actors_simple.cpp | 23 +++------ tdactor/test/actors_workers.cpp | 4 +- tddb/td/db/SqliteConnectionSafe.cpp | 1 - tddb/td/db/TQueue.h | 2 +- tdutils/td/utils/MpmcWaiter.h | 9 +--- tdutils/td/utils/port/detail/EventFdLinux.h | 2 +- tdutils/td/utils/uint128.h | 13 +++-- tdutils/test/EpochBasedMemoryReclamation.cpp | 2 +- tdutils/test/HazardPointers.cpp | 2 +- tdutils/test/List.cpp | 3 +- tdutils/test/MpmcQueue.cpp | 4 +- tdutils/test/MpmcWaiter.cpp | 4 +- tdutils/test/OptionParser.cpp | 9 ++-- tdutils/test/OrderedEventsProcessor.cpp | 2 +- tdutils/test/SharedSlice.cpp | 3 +- tdutils/test/crypto.cpp | 14 +++--- tdutils/test/gzip.cpp | 4 +- tdutils/test/json.cpp | 2 +- tdutils/test/log.cpp | 2 +- tdutils/test/misc.cpp | 29 ++++++----- tdutils/test/pq.cpp | 3 +- test/db.cpp | 8 +-- test/http.cpp | 4 +- test/link.cpp | 6 +-- test/message_entities.cpp | 4 +- test/mtproto.cpp | 10 ++-- test/poll.cpp | 4 +- test/secret.cpp | 9 ++-- test/string_cleaning.cpp | 7 +-- test/tdclient.cpp | 3 +- test/tqueue.cpp | 2 +- 69 files changed, 177 insertions(+), 174 deletions(-) diff --git a/benchmark/bench_tddb.cpp b/benchmark/bench_tddb.cpp index 8e172af01..0b7418dbd 100644 --- a/benchmark/bench_tddb.cpp +++ b/benchmark/bench_tddb.cpp @@ -11,6 +11,7 @@ #include "td/telegram/ServerMessageId.h" #include "td/telegram/UserId.h" +#include "td/db/DbKey.h" #include "td/db/SqliteConnectionSafe.h" #include "td/db/SqliteDb.h" diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 63933522a..afab77752 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4197,7 +4197,7 @@ deleteChatHistory chat_id:int53 remove_from_chat_list:Bool revoke:Bool = Ok; deleteChat chat_id:int53 = Ok; //@description Searches for messages with given words in the chat. Returns the results in reverse chronological order, i.e. in order of decreasing message_id. Cannot be used in secret chats with a non-empty query -//-(searchSecretMessages mmust be used instead), or without an enabled message database. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit +//-(searchSecretMessages must be used instead), or without an enabled message database. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit //@chat_id Identifier of the chat in which to search messages //@query Query to search for //@sender Sender of messages to search for; pass null to search for messages from any sender. Not supported in secret chats @@ -4725,7 +4725,7 @@ addChatMember chat_id:int53 user_id:int53 forward_limit:int32 = Ok; //@chat_id Chat identifier @user_ids Identifiers of the users to be added to the chat. The maximum number of added users is 20 for supergroups and 100 for channels addChatMembers chat_id:int53 user_ids:vector = Ok; -//@description Changes the status of a chat member, needs appropriate privileges. This function is currently not suitable for transferring chat ownership; use transferChatOwnership instead. Use addChatMember or banChatMember if you need to pass some additional parameters +//@description Changes the status of a chat member, needs appropriate privileges. This function is currently not suitable for transferring chat ownership; use transferChatOwnership instead. Use addChatMember or banChatMember if some additional parameters needs to be passed //@chat_id Chat identifier @member_id Member identifier. Chats can be only banned and unbanned in supergroups and channels @status The new status of the member in the chat setChatMemberStatus chat_id:int53 member_id:MessageSender status:ChatMemberStatus = Ok; diff --git a/td/generate/tl_writer_jni_cpp.cpp b/td/generate/tl_writer_jni_cpp.cpp index 54bdab071..d28c582ac 100644 --- a/td/generate/tl_writer_jni_cpp.cpp +++ b/td/generate/tl_writer_jni_cpp.cpp @@ -126,7 +126,7 @@ std::string TD_TL_writer_jni_cpp::gen_type_fetch(const std::string &field_name, if (!(tree_type->flags & tl::FLAG_BARE)) { if (is_type_bare(t)) { - if (field_name != "") { + if (!field_name.empty()) { std::fprintf(stderr, "Do not use non-bare fields with bare type %s\n", name.c_str()); // assert(false); } @@ -174,7 +174,7 @@ std::string TD_TL_writer_jni_cpp::gen_type_fetch(const std::string &field_name, const tl::tl_tree_type *child = static_cast(tree_type->children[0]); res = gen_vector_fetch(field_name, child, vars, parser_type); } else { - if (field_name == "") { + if (field_name.empty()) { return gen_main_class_name(tree_type->type) + "::fetch(env, p)"; } res = "jni::fetch_tl_object<" + gen_main_class_name(tree_type->type) + ">(env, jni::fetch_object(env, p, " + @@ -565,14 +565,14 @@ std::string TD_TL_writer_jni_cpp::gen_additional_function(const std::string &fun " " + class_name_class + " = jni::get_jclass(env, " + gen_java_class_name(gen_class_name(t->name)) + ");\n"; - if (t->args.size()) { + if (!t->args.empty()) { for (std::size_t i = 0; i < t->args.size(); i++) { const tl::arg &a = t->args[i]; assert(a.type->get_type() == tl::NODE_TYPE_TYPE); const tl::tl_tree_type *tree_type = static_cast(a.type); std::string field_name = gen_field_name(a.name); - assert(field_name.size()); + assert(!field_name.empty()); std::string java_field_name = gen_java_field_name(std::string(field_name, 0, field_name.size() - 1)); std::string type_signature = gen_type_signature(tree_type); diff --git a/td/mtproto/Ping.h b/td/mtproto/Ping.h index 25aded068..3d7e7943a 100644 --- a/td/mtproto/Ping.h +++ b/td/mtproto/Ping.h @@ -13,6 +13,7 @@ #include "td/actor/PromiseFuture.h" #include "td/utils/common.h" +#include "td/utils/Slice.h" namespace td { namespace mtproto { diff --git a/td/mtproto/RawConnection.cpp b/td/mtproto/RawConnection.cpp index 2e4ec5dad..c3fa421f4 100644 --- a/td/mtproto/RawConnection.cpp +++ b/td/mtproto/RawConnection.cpp @@ -453,9 +453,10 @@ class RawConnectionHttp final : public RawConnection { unique_ptr RawConnection::create(IPAddress ip_address, SocketFd socket_fd, TransportType transport_type, unique_ptr stats_callback) { #if TD_DARWIN_WATCH_OS - return td::make_unique(ip_address, std::move(stats_callback)); + return td::make_unique(std::move(ip_address), std::move(stats_callback)); #else - return td::make_unique(std::move(socket_fd), transport_type, std::move(stats_callback)); + return td::make_unique(std::move(socket_fd), std::move(transport_type), + std::move(stats_callback)); #endif } diff --git a/td/telegram/CallbackQueriesManager.cpp b/td/telegram/CallbackQueriesManager.cpp index 825674359..b640b9817 100644 --- a/td/telegram/CallbackQueriesManager.cpp +++ b/td/telegram/CallbackQueriesManager.cpp @@ -22,7 +22,6 @@ #include "td/utils/common.h" #include "td/utils/logging.h" -#include "td/utils/Random.h" #include "td/utils/Status.h" namespace td { diff --git a/td/telegram/CallbackQueriesManager.h b/td/telegram/CallbackQueriesManager.h index cbde7fc78..77a220883 100644 --- a/td/telegram/CallbackQueriesManager.h +++ b/td/telegram/CallbackQueriesManager.h @@ -19,8 +19,6 @@ #include "td/utils/buffer.h" #include "td/utils/common.h" -#include - namespace td { class Td; diff --git a/td/telegram/ClientActor.cpp b/td/telegram/ClientActor.cpp index 9352e5d0d..a1b4a8d91 100644 --- a/td/telegram/ClientActor.cpp +++ b/td/telegram/ClientActor.cpp @@ -16,7 +16,7 @@ namespace td { ClientActor::ClientActor(unique_ptr callback, Options options) { Td::Options td_options; - td_options.net_query_stats = options.net_query_stats; + td_options.net_query_stats = std::move(options.net_query_stats); td_ = create_actor("Td", std::move(callback), std::move(td_options)); } diff --git a/td/telegram/ConfigManager.h b/td/telegram/ConfigManager.h index 48662c48e..532719630 100644 --- a/td/telegram/ConfigManager.h +++ b/td/telegram/ConfigManager.h @@ -20,7 +20,6 @@ #include "td/utils/common.h" #include "td/utils/FloodControlStrict.h" #include "td/utils/logging.h" -#include "td/utils/port/IPAddress.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" #include "td/utils/Time.h" diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 2151778ee..9b266b0cf 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -1308,17 +1308,17 @@ class ContactsManager final : public Actor { void load_secret_chat_from_database_impl(SecretChatId secret_chat_id, Promise promise); void on_load_secret_chat_from_database(SecretChatId secret_chat_id, string value, bool force); - void save_user_full(const UserFull *user_full, UserId user_id); + static void save_user_full(const UserFull *user_full, UserId user_id); static string get_user_full_database_key(UserId user_id); static string get_user_full_database_value(const UserFull *user_full); void on_load_user_full_from_database(UserId user_id, string value); - void save_chat_full(const ChatFull *chat_full, ChatId chat_id); + static void save_chat_full(const ChatFull *chat_full, ChatId chat_id); static string get_chat_full_database_key(ChatId chat_id); static string get_chat_full_database_value(const ChatFull *chat_full); void on_load_chat_full_from_database(ChatId chat_id, string value); - void save_channel_full(const ChannelFull *channel_full, ChannelId channel_id); + static void save_channel_full(const ChannelFull *channel_full, ChannelId channel_id); static string get_channel_full_database_key(ChannelId channel_id); static string get_channel_full_database_value(const ChannelFull *channel_full); void on_load_channel_full_from_database(ChannelId channel_id, string value, const char *source); diff --git a/td/telegram/DelayDispatcher.cpp b/td/telegram/DelayDispatcher.cpp index 9341ec915..240502d03 100644 --- a/td/telegram/DelayDispatcher.cpp +++ b/td/telegram/DelayDispatcher.cpp @@ -9,8 +9,6 @@ #include "td/telegram/Global.h" #include "td/telegram/net/NetQueryDispatcher.h" -#include "td/utils/Status.h" - namespace td { void DelayDispatcher::send_with_callback(NetQueryPtr query, ActorShared callback) { diff --git a/td/telegram/DialogParticipant.cpp b/td/telegram/DialogParticipant.cpp index 77818dace..229cbaf5a 100644 --- a/td/telegram/DialogParticipant.cpp +++ b/td/telegram/DialogParticipant.cpp @@ -13,7 +13,6 @@ #include "td/utils/common.h" #include "td/utils/logging.h" -#include "td/utils/misc.h" #include diff --git a/td/telegram/DraftMessage.h b/td/telegram/DraftMessage.h index 836f0af4f..65f8806cd 100644 --- a/td/telegram/DraftMessage.h +++ b/td/telegram/DraftMessage.h @@ -6,6 +6,7 @@ // #pragma once +#include "td/telegram/DialogId.h" #include "td/telegram/InputMessageText.h" #include "td/telegram/MessageId.h" #include "td/telegram/td_api.h" diff --git a/td/telegram/FileReferenceManager.cpp b/td/telegram/FileReferenceManager.cpp index dca2450a4..a5382f3bf 100644 --- a/td/telegram/FileReferenceManager.cpp +++ b/td/telegram/FileReferenceManager.cpp @@ -15,6 +15,7 @@ #include "td/telegram/StickerSetId.h" #include "td/telegram/StickersManager.h" #include "td/telegram/Td.h" +#include "td/telegram/WebPageId.h" #include "td/telegram/WebPagesManager.h" #include "td/utils/algorithm.h" diff --git a/td/telegram/GroupCallManager.cpp b/td/telegram/GroupCallManager.cpp index e798b2368..2a4a590db 100644 --- a/td/telegram/GroupCallManager.cpp +++ b/td/telegram/GroupCallManager.cpp @@ -9,6 +9,7 @@ #include "td/telegram/AccessRights.h" #include "td/telegram/AuthManager.h" #include "td/telegram/ContactsManager.h" +#include "td/telegram/DialogAction.h" #include "td/telegram/Global.h" #include "td/telegram/MessageId.h" #include "td/telegram/MessagesManager.h" diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 199c53887..62dc1cd58 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -4006,6 +4006,8 @@ unique_ptr get_secret_message_content( FormattedText{std::move(message_text), std::move(entities)}, false, &load_data_multipromise); } + default: + break; } if (file == nullptr && !is_media_empty) { LOG(ERROR) << "Received secret message with media, but without a file"; diff --git a/td/telegram/MessageContent.h b/td/telegram/MessageContent.h index c046e6288..f75eb02fd 100644 --- a/td/telegram/MessageContent.h +++ b/td/telegram/MessageContent.h @@ -31,6 +31,7 @@ #include "td/utils/buffer.h" #include "td/utils/common.h" +#include "td/utils/Slice.h" #include "td/utils/Status.h" #include diff --git a/td/telegram/MessagesDb.cpp b/td/telegram/MessagesDb.cpp index 5a300197b..3b11a1b8d 100644 --- a/td/telegram/MessagesDb.cpp +++ b/td/telegram/MessagesDb.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include namespace td { @@ -850,8 +851,9 @@ class MessagesDbImpl final : public MessagesDbSyncInterface { SqliteStatement delete_scheduled_message_stmt_; SqliteStatement delete_scheduled_server_message_stmt_; - Result> get_messages_impl(GetMessagesStmt &stmt, DialogId dialog_id, - MessageId from_message_id, int32 offset, int32 limit) { + static Result> get_messages_impl(GetMessagesStmt &stmt, DialogId dialog_id, + MessageId from_message_id, int32 offset, + int32 limit) { LOG_CHECK(dialog_id.is_valid()) << dialog_id; CHECK(from_message_id.is_valid()); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 5387dab17..63fb4dd36 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -18167,7 +18167,7 @@ void MessagesManager::on_reorder_dialog_filters(vector dialog_fi if (result.is_error()) { // TODO rollback dialog_filters_ changes if error isn't 429 } else { - if (set_dialog_filters_order(server_dialog_filters_, dialog_filter_ids)) { + if (set_dialog_filters_order(server_dialog_filters_, std::move(dialog_filter_ids))) { save_dialog_filters(); } } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 49c693a7e..bfb890c2a 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -35,6 +35,7 @@ #include "td/telegram/MessageSearchFilter.h" #include "td/telegram/MessageThreadInfo.h" #include "td/telegram/MessageTtlSetting.h" +#include "td/telegram/net/DcId.h" #include "td/telegram/net/NetQuery.h" #include "td/telegram/Notification.h" #include "td/telegram/NotificationGroupId.h" @@ -1816,7 +1817,7 @@ class MessagesManager final : public Actor { void on_message_media_edited(DialogId dialog_id, MessageId message_id, FileId file_id, FileId thumbnail_file_id, bool was_uploaded, bool was_thumbnail_uploaded, string file_reference, - int32 scheduled_date, uint64 generation, Result &&result); + int32 schedule_date, uint64 generation, Result &&result); static MessageId get_persistent_message_id(const Dialog *d, MessageId message_id); diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index b4fb66d62..79921e5bc 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -6643,7 +6643,7 @@ string StickersManager::get_language_emojis_database_key(const string &language_ } vector StickersManager::search_language_emojis(const string &language_code, const string &text, - bool exact_match) const { + bool exact_match) { LOG(INFO) << "Search for \"" << text << "\" in language " << language_code; auto key = get_language_emojis_database_key(language_code, text); if (exact_match) { diff --git a/td/telegram/StickersManager.h b/td/telegram/StickersManager.h index 1c8d06fb4..0b81fc996 100644 --- a/td/telegram/StickersManager.h +++ b/td/telegram/StickersManager.h @@ -6,6 +6,7 @@ // #pragma once +#include "td/telegram/DialogId.h" #include "td/telegram/files/FileId.h" #include "td/telegram/files/FileSourceId.h" #include "td/telegram/FullMessageId.h" @@ -658,7 +659,7 @@ class StickersManager final : public Actor { void on_get_language_codes(const string &key, Result> &&result); - vector search_language_emojis(const string &language_code, const string &text, bool exact_match) const; + static vector search_language_emojis(const string &language_code, const string &text, bool exact_match); void load_emoji_keywords(const string &language_code, Promise &&promise); diff --git a/td/telegram/StorageManager.cpp b/td/telegram/StorageManager.cpp index 492c321b1..11384ad1c 100644 --- a/td/telegram/StorageManager.cpp +++ b/td/telegram/StorageManager.cpp @@ -7,6 +7,7 @@ #include "td/telegram/StorageManager.h" #include "td/telegram/ConfigShared.h" +#include "td/telegram/DialogId.h" #include "td/telegram/files/FileGcWorker.h" #include "td/telegram/files/FileStatsWorker.h" #include "td/telegram/Global.h" diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 960bec119..82e198b43 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6,7 +6,6 @@ // #include "td/telegram/Td.h" -#include "td/telegram/AccessRights.h" #include "td/telegram/AnimationsManager.h" #include "td/telegram/AudiosManager.h" #include "td/telegram/AuthManager.h" @@ -170,7 +169,7 @@ void Td::ResultHandler::on_result(NetQueryPtr query) { void Td::ResultHandler::send_query(NetQueryPtr query) { td->add_handler(query->id(), shared_from_this()); - td->send(std::move(query)); + send(std::move(query)); } class GetPromoDataQuery final : public Td::ResultHandler { diff --git a/td/telegram/ThemeManager.cpp b/td/telegram/ThemeManager.cpp index b70cf8e06..c2c219992 100644 --- a/td/telegram/ThemeManager.cpp +++ b/td/telegram/ThemeManager.cpp @@ -19,6 +19,7 @@ #include "td/utils/logging.h" #include "td/utils/Random.h" #include "td/utils/Time.h" +#include "td/utils/tl_helpers.h" namespace td { diff --git a/td/telegram/TopDialogManager.cpp b/td/telegram/TopDialogManager.cpp index fda8a0b6a..853141ed8 100644 --- a/td/telegram/TopDialogManager.cpp +++ b/td/telegram/TopDialogManager.cpp @@ -21,15 +21,12 @@ #include "td/telegram/Td.h" #include "td/telegram/TdDb.h" #include "td/telegram/TdParameters.h" -#include "td/telegram/telegram_api.h" #include "td/utils/algorithm.h" #include "td/utils/buffer.h" #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/port/Clocks.h" -#include "td/utils/ScopeGuard.h" -#include "td/utils/Slice.h" #include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/tl_helpers.h" @@ -124,11 +121,14 @@ class ResetTopPeerRatingQuery final : public Td::ResultHandler { void on_error(uint64 id, Status status) final { if (!td->messages_manager_->on_get_dialog_error(dialog_id_, status, "ResetTopPeerRatingQuery")) { - LOG(INFO) << "Receive error for resetTopPeerRating: " << status; + LOG(INFO) << "Receive error for ResetTopPeerRatingQuery: " << status; } } }; +TopDialogManager::TopDialogManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) { +} + void TopDialogManager::update_is_enabled(bool is_enabled) { if (td_->auth_manager_ == nullptr || !td_->auth_manager_->is_authorized() || td_->auth_manager_->is_bot()) { return; diff --git a/td/telegram/TopDialogManager.h b/td/telegram/TopDialogManager.h index 3cf04d54f..a6f7005a2 100644 --- a/td/telegram/TopDialogManager.h +++ b/td/telegram/TopDialogManager.h @@ -7,12 +7,14 @@ #pragma once #include "td/telegram/DialogId.h" +#include "td/telegram/telegram_api.h" #include "td/telegram/TopDialogCategory.h" #include "td/actor/actor.h" #include "td/actor/PromiseFuture.h" #include "td/utils/common.h" +#include "td/utils/Status.h" #include "td/utils/Time.h" #include @@ -24,8 +26,7 @@ class Td; class TopDialogManager final : public Actor { public: - TopDialogManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) { - } + TopDialogManager(Td *td, ActorShared<> parent); void init(); @@ -67,7 +68,7 @@ class TopDialogManager final : public Actor { size_t limit; Promise> promise; }; - std::vector pending_get_top_dialogs_; + vector pending_get_top_dialogs_; struct TopDialog { DialogId dialog_id; @@ -80,7 +81,7 @@ class TopDialogManager final : public Actor { struct TopDialogs { bool is_dirty = false; double rating_timestamp = 0; - std::vector dialogs; + vector dialogs; }; template friend void store(const TopDialog &top_dialog, StorerT &storer); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 61205ed52..092f977bc 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -1830,7 +1830,7 @@ class CliClient final : public Actor { send_request(td_api::make_object( as_input_passport_element(passport_element_type, arg, op == "spes"), password)); } else if (op == "dpe") { - string passport_element_type = std::move(args); + const string &passport_element_type = args; send_request(td_api::make_object(as_passport_element_type(passport_element_type))); } else if (op == "ppn") { send_request(td_api::make_object(args)); @@ -1950,7 +1950,7 @@ class CliClient final : public Actor { send_request(td_api::make_object( td_api::make_object(string(), first_name, last_name, string(), as_user_id(user_id)), false)); } else if (op == "spn") { - string user_id = std::move(args); + const string &user_id = args; send_request(td_api::make_object(as_user_id(user_id))); } else if (op == "ImportContacts" || op == "cic") { vector contacts_str = full_split(args, ';'); @@ -2012,7 +2012,7 @@ class CliClient final : public Actor { offset, as_limit(limit), op == "ghl")); } } else if (op == "gcsm") { - string chat_id = std::move(args); + const string &chat_id = args; send_request(td_api::make_object(as_chat_id(chat_id))); } else if (op == "gmpf") { string chat_id; @@ -2141,10 +2141,10 @@ class CliClient final : public Actor { send_request(td_api::make_object(language_database_path, language_pack, language_code, key)); } else if (op == "synclp") { - string language_code = std::move(args); + const string &language_code = args; send_request(td_api::make_object(language_code)); } else if (op == "acslp") { - string language_code = std::move(args); + const string &language_code = args; send_request(td_api::make_object(language_code)); } else if (op == "sclp") { string language_code; @@ -2438,10 +2438,10 @@ class CliClient final : public Actor { get_args(args, chat_id, category); send_request(td_api::make_object(get_top_chat_category(category), as_chat_id(chat_id))); } else if (op == "gsssn") { - string title = std::move(args); + const string &title = args; send_request(td_api::make_object(title)); } else if (op == "cssn") { - string name = std::move(args); + const string &name = args; send_request(td_api::make_object(name)); } else if (op == "usf" || op == "usfa") { td_api::object_ptr input_sticker; @@ -2551,7 +2551,7 @@ class CliClient final : public Actor { get_args(args, chat_id, member_id); send_request(td_api::make_object(as_chat_id(chat_id), as_message_sender(member_id))); } else if (op == "GetChatAdministrators") { - string chat_id = std::move(args); + const string &chat_id = args; send_request(td_api::make_object(as_chat_id(chat_id))); } else if (op == "GetSupergroupAdministrators" || op == "GetSupergroupBanned" || op == "GetSupergroupBots" || op == "GetSupergroupContacts" || op == "GetSupergroupMembers" || op == "GetSupergroupRestricted" || @@ -2607,7 +2607,7 @@ class CliClient final : public Actor { get_args(args, chat_id, message_id); send_request(td_api::make_object(as_chat_id(chat_id), as_message_id(message_id))); } else if (op == "gcpm") { - string chat_id = std::move(args); + const string &chat_id = args; send_request(td_api::make_object(as_chat_id(chat_id))); } else if (op == "gms") { string chat_id; @@ -2717,7 +2717,7 @@ class CliClient final : public Actor { } else if (op == "cuf") { send_request(td_api::make_object(as_file_id(args))); } else if (op == "delf" || op == "DeleteFile") { - string file_id = std::move(args); + const string &file_id = args; send_request(td_api::make_object(as_file_id(file_id))); } else if (op == "dm" || op == "dmr") { string chat_id; @@ -2847,7 +2847,7 @@ class CliClient final : public Actor { send_request(td_api::make_object(as_group_call_id(group_call_id), is_paused)); } else if (op == "egcss") { - string group_call_id = std::move(args); + const string &group_call_id = args; send_request(td_api::make_object(as_group_call_id(group_call_id))); } else if (op == "sgct") { string chat_id; @@ -2899,7 +2899,7 @@ class CliClient final : public Actor { send_request(td_api::make_object(as_group_call_id(chat_id), title, record_video, use_portrait_orientation)); } else if (op == "egcr") { - string chat_id = std::move(args); + const string &chat_id = args; send_request(td_api::make_object(as_group_call_id(chat_id))); } else if (op == "tgcpim") { string group_call_id; @@ -2933,7 +2933,7 @@ class CliClient final : public Actor { } else if (op == "dgc") { send_request(td_api::make_object(as_group_call_id(args))); } else if (op == "rpcil") { - string chat_id = std::move(args); + const string &chat_id = args; send_request(td_api::make_object(as_chat_id(chat_id))); } else if (op == "ccilt") { string chat_id; @@ -2955,7 +2955,7 @@ class CliClient final : public Actor { get_args(args, chat_id, invite_link); send_request(td_api::make_object(as_chat_id(chat_id), invite_link)); } else if (op == "gcilc") { - string chat_id = std::move(args); + const string &chat_id = args; send_request(td_api::make_object(as_chat_id(chat_id))); } else if (op == "gcil") { string chat_id; @@ -3731,10 +3731,10 @@ class CliClient final : public Actor { get_args(args, supergroup_id, force); send_request(td_api::make_object(as_supergroup_id(supergroup_id), force)); } else if (op == "gcltac") { - string chat_id = std::move(args); + const string &chat_id = args; send_request(td_api::make_object(as_chat_id(chat_id))); } else if (op == "actl" || op == "actla" || begins_with(op, "actl-")) { - string chat_id = std::move(args); + const string &chat_id = args; send_request(td_api::make_object(as_chat_id(chat_id), as_chat_list(op))); } else if (op == "gcf") { send_request(td_api::make_object(as_chat_filter_id(args))); @@ -3765,7 +3765,7 @@ class CliClient final : public Actor { get_args(args, chat_id, title); send_request(td_api::make_object(as_chat_id(chat_id), title)); } else if (op == "scpe") { - string chat_id = std::move(args); + const string &chat_id = args; send_request(td_api::make_object(as_chat_id(chat_id), nullptr)); } else if (op == "scpp") { string chat_id; @@ -4030,7 +4030,7 @@ class CliClient final : public Actor { get_args(args, chat_id, message_id); send_request(td_api::make_object(as_chat_id(chat_id), as_message_id(message_id))); } else if (op == "uacm") { - string chat_id = std::move(args); + const string &chat_id = args; send_request(td_api::make_object(as_chat_id(chat_id))); } else if (op == "grib") { send_request(td_api::make_object()); @@ -4088,10 +4088,10 @@ class CliClient final : public Actor { send_request(td_api::make_object(td_api::make_object( as_input_file(animation), to_double(main_frame_timestamp)))); } else if (op == "sh") { - auto prefix = std::move(args); + const string &prefix = args; send_request(td_api::make_object(prefix, 10)); } else if (op == "rrh") { - auto hashtag = std::move(args); + const string &hashtag = args; send_request(td_api::make_object(hashtag)); } else if (op == "view" || op == "viewt") { string chat_id; @@ -4115,16 +4115,16 @@ class CliClient final : public Actor { send_request( td_api::make_object(as_chat_id(chat_id), as_message_id(message_id))); } else if (op == "gilt") { - string link = std::move(args); + const string &link = args; send_request(td_api::make_object(link)); } else if (op == "geli") { - string link = std::move(args); + const string &link = args; send_request(td_api::make_object(link)); } else if (op == "gel" || op == "gelw") { - string link = std::move(args); + const string &link = args; send_request(td_api::make_object(link, op == "gelw")); } else if (op == "racm") { - string chat_id = std::move(args); + const string &chat_id = args; send_request(td_api::make_object(as_chat_id(chat_id))); } else if (op == "tre") { send_request(td_api::make_object( @@ -4175,7 +4175,7 @@ class CliClient final : public Actor { get_args(args, group_id, max_notification_id); send_request(td_api::make_object(group_id, max_notification_id)); } else if (op == "rcab") { - string chat_id = std::move(args); + const string &chat_id = args; send_request(td_api::make_object(as_chat_id(chat_id))); } else if (op == "rc") { string chat_id; @@ -4354,7 +4354,7 @@ class CliClient final : public Actor { execute(std::move(request)); } } else if (op == "gltvl" || op == "gltvle" || op == "gtag") { - string tag = std::move(args); + const string &tag = args; auto request = td_api::make_object(tag); if (op == "gltvl") { send_request(std::move(request)); diff --git a/td/telegram/files/FileDb.cpp b/td/telegram/files/FileDb.cpp index 06a0ec530..46b0bb115 100644 --- a/td/telegram/files/FileDb.cpp +++ b/td/telegram/files/FileDb.cpp @@ -139,7 +139,7 @@ class FileDb final : public FileDbInterface { pmc.commit_transaction().ensure(); } - void optimize_refs(const std::vector ids, FileDbId main_id) { + void optimize_refs(std::vector ids, FileDbId main_id) { LOG(INFO) << "Optimize " << ids.size() << " ids in file database to " << main_id.get(); auto &pmc = file_pmc(); pmc.begin_write_transaction().ensure(); diff --git a/td/telegram/files/FileGcWorker.cpp b/td/telegram/files/FileGcWorker.cpp index e1f782f37..32cc8b1b4 100644 --- a/td/telegram/files/FileGcWorker.cpp +++ b/td/telegram/files/FileGcWorker.cpp @@ -18,7 +18,6 @@ #include "td/utils/misc.h" #include "td/utils/port/Clocks.h" #include "td/utils/port/path.h" -#include "td/utils/Status.h" #include "td/utils/Time.h" #include diff --git a/td/telegram/files/FileStatsWorker.cpp b/td/telegram/files/FileStatsWorker.cpp index a5a39bb31..f06971c5e 100644 --- a/td/telegram/files/FileStatsWorker.cpp +++ b/td/telegram/files/FileStatsWorker.cpp @@ -27,7 +27,6 @@ #include "td/utils/port/Stat.h" #include "td/utils/Slice.h" #include "td/utils/SliceBuilder.h" -#include "td/utils/Status.h" #include "td/utils/Time.h" #include "td/utils/tl_parsers.h" diff --git a/td/telegram/misc.h b/td/telegram/misc.h index 169c9d1bd..00cc46e1d 100644 --- a/td/telegram/misc.h +++ b/td/telegram/misc.h @@ -7,7 +7,6 @@ #pragma once #include "td/utils/common.h" -#include "td/utils/Slice.h" namespace td { diff --git a/td/telegram/net/NetStatsManager.h b/td/telegram/net/NetStatsManager.h index 1dad82480..9f8a7ada4 100644 --- a/td/telegram/net/NetStatsManager.h +++ b/td/telegram/net/NetStatsManager.h @@ -132,12 +132,13 @@ class NetStatsManager final : public Actor { f(call_net_stats_, CALL_NET_STATS_ID, CSlice("calls"), FileType::None); } - void add_network_stats_impl(NetStatsInfo &info, const NetworkStatsEntry &entry); + static void add_network_stats_impl(NetStatsInfo &info, const NetworkStatsEntry &entry); void start_up() final; - void update(NetStatsInfo &info, bool force_save); + + static void update(NetStatsInfo &info, bool force_save); static void save_stats(NetStatsInfo &info, NetType net_type); - void info_loop(NetStatsInfo &info); + static void info_loop(NetStatsInfo &info); void on_stats_updated(size_t id); void on_net_type_updated(NetType net_type); diff --git a/td/telegram/td_emscripten.cpp b/td/telegram/td_emscripten.cpp index 2022a59d6..17dfa0493 100644 --- a/td/telegram/td_emscripten.cpp +++ b/td/telegram/td_emscripten.cpp @@ -34,7 +34,7 @@ EMSCRIPTEN_KEEPALIVE double td_emscripten_get_timeout() { } } -int main(void) { +int main() { emscripten_exit_with_live_runtime(); return 0; } diff --git a/tdactor/example/example.cpp b/tdactor/example/example.cpp index 119d18d94..a97242092 100644 --- a/tdactor/example/example.cpp +++ b/tdactor/example/example.cpp @@ -35,7 +35,7 @@ class MainActor final : public td::Actor { td::ActorOwn worker_; }; -int main(void) { +int main() { td::ConcurrentScheduler scheduler; scheduler.init(4 /*threads_count*/); scheduler.start(); diff --git a/tdactor/td/actor/PromiseFuture.h b/tdactor/td/actor/PromiseFuture.h index ba474cc9e..23aff5f61 100644 --- a/tdactor/td/actor/PromiseFuture.h +++ b/tdactor/td/actor/PromiseFuture.h @@ -407,10 +407,10 @@ class CancellablePromise final : public PromiseT { CancellablePromise(CancellationToken cancellation_token, ArgsT &&... args) : PromiseT(std::forward(args)...), cancellation_token_(std::move(cancellation_token)) { } - virtual bool is_cancellable() const { + bool is_cancellable() const final { return true; } - virtual bool is_canceled() const { + bool is_canceled() const final { return static_cast(cancellation_token_); } diff --git a/tdactor/test/actors_bugs.cpp b/tdactor/test/actors_bugs.cpp index 0e4843986..aaa1252ad 100644 --- a/tdactor/test/actors_bugs.cpp +++ b/tdactor/test/actors_bugs.cpp @@ -50,9 +50,9 @@ TEST(MultiTimeout, bug) { } class TimeoutManager final : public td::Actor { - public: static td::int32 count; + public: TimeoutManager() { count++; diff --git a/tdactor/test/actors_main.cpp b/tdactor/test/actors_main.cpp index a16935d35..cf19553b7 100644 --- a/tdactor/test/actors_main.cpp +++ b/tdactor/test/actors_main.cpp @@ -19,8 +19,6 @@ #include #include -namespace { - template static typename ContainerT::value_type &rand_elem(ContainerT &cont) { CHECK(0 < cont.size() && cont.size() <= static_cast(std::numeric_limits::max())); @@ -338,7 +336,6 @@ class SimpleActor final : public td::Actor { td::uint32 q_ = 1; td::uint32 p_ = 0; }; -} // namespace class SendToDead final : public td::Actor { public: @@ -470,7 +467,7 @@ class XContext final : public td::ActorContext { void validate() { CHECK(x == 1234); } - ~XContext() { + ~XContext() final { x = 0; } int x = 1234; diff --git a/tdactor/test/actors_simple.cpp b/tdactor/test/actors_simple.cpp index 96c00186f..47140c822 100644 --- a/tdactor/test/actors_simple.cpp +++ b/tdactor/test/actors_simple.cpp @@ -9,13 +9,11 @@ #include "td/actor/MultiPromise.h" #include "td/actor/PromiseFuture.h" #include "td/actor/SleepActor.h" -#include "td/actor/Timeout.h" #include "td/utils/common.h" #include "td/utils/logging.h" #include "td/utils/MpscPollableQueue.h" #include "td/utils/Observer.h" -#include "td/utils/port/detail/PollableFd.h" #include "td/utils/port/FileFd.h" #include "td/utils/port/thread.h" #include "td/utils/Slice.h" @@ -27,8 +25,6 @@ #include #include -namespace { - static const size_t BUF_SIZE = 1024 * 1024; static char buf[BUF_SIZE]; static char buf2[BUF_SIZE]; @@ -199,7 +195,6 @@ class PrintChar final : public td::Actor { char char_; int cnt_; }; -} // namespace // // Yield must add actor to the end of queue @@ -315,7 +310,6 @@ TEST(Actors, open_close) { scheduler.finish(); } -namespace { class MsgActor : public td::Actor { public: virtual void msg() = 0; @@ -353,7 +347,6 @@ class MasterActor final : public MsgActor { } td::uint64 alive_ = 123456789; }; -} // namespace TEST(Actors, call_after_destruct) { td::Scheduler scheduler; @@ -655,9 +648,9 @@ TEST(Actors, send_from_other_threads) { class DelayedCall final : public td::Actor { public: - void on_called(int *order) { - CHECK(*order == 0); - *order = 1; + void on_called(int *step) { + CHECK(*step == 0); + *step = 1; } }; @@ -666,21 +659,21 @@ class MultiPromiseSendClosureLaterTest final : public td::Actor { void start_up() final { delayed_call_ = td::create_actor("DelayedCall").release(); mpa_.add_promise(td::PromiseCreator::lambda([this](td::Unit) { - CHECK(order_ == 1); - order_++; + CHECK(step_ == 1); + step_++; td::Scheduler::instance()->finish(); })); auto lock = mpa_.get_promise(); - td::send_closure_later(delayed_call_, &DelayedCall::on_called, &order_); + td::send_closure_later(delayed_call_, &DelayedCall::on_called, &step_); lock.set_value(td::Unit()); } void tear_down() final { - CHECK(order_ == 2); + CHECK(step_ == 2); } private: - int order_ = 0; + int step_ = 0; td::MultiPromiseActor mpa_{"MultiPromiseActor"}; td::ActorId delayed_call_; }; diff --git a/tdactor/test/actors_workers.cpp b/tdactor/test/actors_workers.cpp index 172f165a9..9873d1e2d 100644 --- a/tdactor/test/actors_workers.cpp +++ b/tdactor/test/actors_workers.cpp @@ -7,11 +7,10 @@ #include "td/actor/actor.h" #include "td/actor/ConcurrentScheduler.h" +#include "td/utils/common.h" #include "td/utils/SliceBuilder.h" #include "td/utils/tests.h" -namespace { - class PowerWorker final : public td::Actor { public: class Callback { @@ -125,7 +124,6 @@ static void test_workers(int threads_n, int workers_n, int queries_n, int query_ // sched.test_one_thread_run(); } -} // namespace TEST(Actors, workers_big_query_one_thread) { test_workers(0, 10, 1000, 300000); diff --git a/tddb/td/db/SqliteConnectionSafe.cpp b/tddb/td/db/SqliteConnectionSafe.cpp index de39ce95e..6fa0a78e6 100644 --- a/tddb/td/db/SqliteConnectionSafe.cpp +++ b/tddb/td/db/SqliteConnectionSafe.cpp @@ -9,7 +9,6 @@ #include "td/utils/common.h" #include "td/utils/format.h" #include "td/utils/logging.h" -#include "td/utils/port/Stat.h" namespace td { diff --git a/tddb/td/db/TQueue.h b/tddb/td/db/TQueue.h index 8e84ae9a9..7e37eb6ce 100644 --- a/tddb/td/db/TQueue.h +++ b/tddb/td/db/TQueue.h @@ -54,9 +54,9 @@ class TQueue { struct Event { EventId id; + int32 expires_at{0}; Slice data; int64 extra{0}; - int32 expires_at{0}; }; struct RawEvent { diff --git a/tdutils/td/utils/MpmcWaiter.h b/tdutils/td/utils/MpmcWaiter.h index e4b3baa87..7017d75b5 100644 --- a/tdutils/td/utils/MpmcWaiter.h +++ b/tdutils/td/utils/MpmcWaiter.h @@ -25,7 +25,7 @@ class MpmcEagerWaiter { int yields; uint32 worker_id; }; - void init_slot(Slot &slot, uint32 worker_id) { + static void init_slot(Slot &slot, uint32 worker_id) { slot.yields = 0; slot.worker_id = worker_id; } @@ -33,7 +33,6 @@ class MpmcEagerWaiter { if (slot.yields < RoundsTillSleepy) { td::this_thread::yield(); slot.yields++; - return; } else if (slot.yields == RoundsTillSleepy) { auto state = state_.load(std::memory_order_relaxed); if (!State::has_worker(state)) { @@ -50,7 +49,6 @@ class MpmcEagerWaiter { } td::this_thread::yield(); slot.yields = 0; - return; } else if (slot.yields < RoundsTillAsleep) { auto state = state_.load(std::memory_order_acquire); if (State::still_sleepy(state, slot.worker_id)) { @@ -59,7 +57,6 @@ class MpmcEagerWaiter { return; } slot.yields = 0; - return; } else { auto state = state_.load(std::memory_order_acquire); if (State::still_sleepy(state, slot.worker_id)) { @@ -69,7 +66,6 @@ class MpmcEagerWaiter { } } slot.yields = 0; - return; } } @@ -78,7 +74,6 @@ class MpmcEagerWaiter { notify_cold(); } slot.yields = 0; - return; } void close() { @@ -195,7 +190,7 @@ class MpmcSleepyWaiter { // If possible - in Search state // - void init_slot(Slot &slot, int32 worker_id) { + static void init_slot(Slot &slot, int32 worker_id) { slot.state_ = Slot::State::Work; slot.unpark_flag_ = false; slot.worker_id = worker_id; diff --git a/tdutils/td/utils/port/detail/EventFdLinux.h b/tdutils/td/utils/port/detail/EventFdLinux.h index 87e428949..9fd00f27b 100644 --- a/tdutils/td/utils/port/detail/EventFdLinux.h +++ b/tdutils/td/utils/port/detail/EventFdLinux.h @@ -26,7 +26,7 @@ class EventFdLinux final : public EventFdBase { EventFdLinux(); EventFdLinux(EventFdLinux &&) noexcept; EventFdLinux &operator=(EventFdLinux &&) noexcept; - ~EventFdLinux() override; + ~EventFdLinux() final; void init() final; diff --git a/tdutils/td/utils/uint128.h b/tdutils/td/utils/uint128.h index 48833179a..5cc1a4e28 100644 --- a/tdutils/td/utils/uint128.h +++ b/tdutils/td/utils/uint128.h @@ -128,12 +128,14 @@ class uint128_emulated { *mod_res = from; } uint128 div(uint128 other) const { - uint128 a, b; + uint128 a; + uint128 b; divmod(other, &a, &b); return a; } uint128 mod(uint128 other) const { - uint128 a, b; + uint128 a; + uint128 b; divmod(other, &a, &b); return b; } @@ -151,7 +153,8 @@ class uint128_emulated { uy = uy.negate(); } - uint128 t_quot, t_mod; + uint128 t_quot; + uint128 t_mod; x.divmod(uy, &t_quot, &t_mod); *quot = t_quot.lo(); *rem = t_mod.lo(); @@ -266,8 +269,8 @@ class uint128_intrinsic { } void divmod_signed(int64 y, int64 *quot, int64 *rem) const { CHECK(y != 0); - *quot = (int64)(signed_value() / y); - *rem = (int64)(signed_value() % y); + *quot = static_cast(signed_value() / y); + *rem = static_cast(signed_value() % y); } private: diff --git a/tdutils/test/EpochBasedMemoryReclamation.cpp b/tdutils/test/EpochBasedMemoryReclamation.cpp index 66131545e..b721d2e19 100644 --- a/tdutils/test/EpochBasedMemoryReclamation.cpp +++ b/tdutils/test/EpochBasedMemoryReclamation.cpp @@ -42,7 +42,7 @@ TEST(EpochBaseMemoryReclamation, stress) { locker.retire(); } if (td::Random::fast(0, 5) == 0) { - std::string *new_str = new std::string(td::Random::fast_bool() ? "one" : "twotwo"); + auto *new_str = new td::string(td::Random::fast_bool() ? "one" : "twotwo"); if (node.name_.compare_exchange_strong(str, new_str, std::memory_order_acq_rel)) { locker.retire(str); } else { diff --git a/tdutils/test/HazardPointers.cpp b/tdutils/test/HazardPointers.cpp index 9b6b9a81e..f18a677f1 100644 --- a/tdutils/test/HazardPointers.cpp +++ b/tdutils/test/HazardPointers.cpp @@ -36,7 +36,7 @@ TEST(HazardPointers, stress) { } holder.clear(); if (td::Random::fast(0, 5) == 0) { - std::string *new_str = new std::string(td::Random::fast_bool() ? "one" : "twotwo"); + auto *new_str = new td::string(td::Random::fast_bool() ? "one" : "twotwo"); if (node.name_.compare_exchange_strong(str, new_str, std::memory_order_acq_rel)) { hazard_pointers.retire(thread_id, str); } else { diff --git a/tdutils/test/List.cpp b/tdutils/test/List.cpp index 0d29b0e6c..ca6c8b2da 100644 --- a/tdutils/test/List.cpp +++ b/tdutils/test/List.cpp @@ -110,7 +110,8 @@ static void do_run_list_test(ListRootT &root, std::atomic &id) { nodes[i] = std::move(nodes[j]); }; auto validate = [&] { - std::multiset in_list, not_in_list; + std::multiset in_list; + std::multiset not_in_list; for (auto &node : nodes) { if (get_data(node).in_list.get()) { in_list.insert(get_data(node).value.get()); diff --git a/tdutils/test/MpmcQueue.cpp b/tdutils/test/MpmcQueue.cpp index 4b084f137..6cdfb73bb 100644 --- a/tdutils/test/MpmcQueue.cpp +++ b/tdutils/test/MpmcQueue.cpp @@ -50,7 +50,7 @@ TEST(OneValue, stress) { std::vector threads; td::OneValue value; for (size_t i = 0; i < 2; i++) { - threads.push_back(td::thread([&, id = i] { + threads.emplace_back([&, id = i] { for (td::uint64 round = 1; round < 100000; round++) { if (id == 0) { value.reset(); @@ -77,7 +77,7 @@ TEST(OneValue, stress) { } } } - })); + }); } for (auto &thread : threads) { thread.join(); diff --git a/tdutils/test/MpmcWaiter.cpp b/tdutils/test/MpmcWaiter.cpp index 1f36e3e54..c23c0942a 100644 --- a/tdutils/test/MpmcWaiter.cpp +++ b/tdutils/test/MpmcWaiter.cpp @@ -39,7 +39,7 @@ static void test_waiter_stress_one_one() { } } else { typename W::Slot slot; - waiter->init_slot(slot, id); + W::init_slot(slot, id); for (size_t i = 1; i <= write_cnt; i++) { while (true) { auto x = value.load(std::memory_order_relaxed); @@ -106,7 +106,7 @@ static void test_waiter_stress() { } } else if (id > 10 && id - 10 <= read_n) { typename W::Slot slot; - waiter->init_slot(slot, id); + W::init_slot(slot, id); while (true) { auto x = read_pos.load(std::memory_order_relaxed); if (x == end_pos) { diff --git a/tdutils/test/OptionParser.cpp b/tdutils/test/OptionParser.cpp index ec6ab0595..a0f0d47cb 100644 --- a/tdutils/test/OptionParser.cpp +++ b/tdutils/test/OptionParser.cpp @@ -17,7 +17,7 @@ TEST(OptionParser, run) { td::string exename = "exename"; td::vector args; auto run_option_parser = [&](td::string command_line) { - args = td::full_split(command_line, ' '); + args = td::full_split(std::move(command_line), ' '); td::vector argv; argv.push_back(&exename[0]); for (auto &arg : args) { @@ -29,10 +29,11 @@ TEST(OptionParser, run) { td::uint64 chosen_options = 0; td::vector chosen_parameters; auto test_success = [&](td::string command_line, td::uint64 expected_options, - td::vector expected_parameters, td::vector expected_result) { + const td::vector &expected_parameters, + const td::vector &expected_result) { chosen_options = 0; chosen_parameters.clear(); - auto result = run_option_parser(command_line); + auto result = run_option_parser(std::move(command_line)); ASSERT_TRUE(result.is_ok()); ASSERT_EQ(expected_options, chosen_options); ASSERT_EQ(expected_parameters, chosen_parameters); @@ -42,7 +43,7 @@ TEST(OptionParser, run) { } }; auto test_fail = [&](td::string command_line) { - auto result = run_option_parser(command_line); + auto result = run_option_parser(std::move(command_line)); ASSERT_TRUE(result.is_error()); }; diff --git a/tdutils/test/OrderedEventsProcessor.cpp b/tdutils/test/OrderedEventsProcessor.cpp index 8e68819bb..c2da3bf4f 100644 --- a/tdutils/test/OrderedEventsProcessor.cpp +++ b/tdutils/test/OrderedEventsProcessor.cpp @@ -19,7 +19,7 @@ TEST(OrderedEventsProcessor, random) { std::vector> v; for (int i = 0; i < n; i++) { auto shift = td::Random::fast_bool() ? td::Random::fast(0, d) : td::Random::fast(0, 1) * d; - v.push_back({i + shift, i + offset}); + v.emplace_back(i + shift, i + offset); } std::sort(v.begin(), v.end()); diff --git a/tdutils/test/SharedSlice.cpp b/tdutils/test/SharedSlice.cpp index 0fb101d28..1a39a714c 100644 --- a/tdutils/test/SharedSlice.cpp +++ b/tdutils/test/SharedSlice.cpp @@ -61,7 +61,8 @@ TEST(SharedSlice, Hands) { { td::Stage stage; - td::SharedSlice a, b; + td::SharedSlice a; + td::SharedSlice b; td::vector threads(2); for (int i = 0; i < 2; i++) { threads[i] = td::thread([i, &stage, &a, &b] { diff --git a/tdutils/test/crypto.cpp b/tdutils/test/crypto.cpp index c7abbd61d..2d6decc24 100644 --- a/tdutils/test/crypto.cpp +++ b/tdutils/test/crypto.cpp @@ -72,7 +72,7 @@ TEST(Crypto, AesCtrState) { state.init(as_slice(key), as_slice(iv)); td::string t(length, '\0'); std::size_t pos = 0; - for (auto str : td::rand_split(td::string(length, '\0'))) { + for (const auto &str : td::rand_split(td::string(length, '\0'))) { auto len = str.size(); state.encrypt(td::Slice(s).substr(pos, len), td::MutableSlice(t).substr(pos, len)); pos += len; @@ -80,7 +80,7 @@ TEST(Crypto, AesCtrState) { ASSERT_EQ(answers1[i], td::crc32(t)); state.init(as_slice(key), as_slice(iv)); pos = 0; - for (auto str : td::rand_split(td::string(length, '\0'))) { + for (const auto &str : td::rand_split(td::string(length, '\0'))) { auto len = str.size(); state.decrypt(td::Slice(t).substr(pos, len), td::MutableSlice(t).substr(pos, len)); pos += len; @@ -92,7 +92,7 @@ TEST(Crypto, AesCtrState) { } state.init(as_slice(key), as_slice(iv)); pos = 0; - for (auto str : td::rand_split(td::string(length, '\0'))) { + for (const auto &str : td::rand_split(td::string(length, '\0'))) { auto len = str.size(); state.encrypt(td::Slice(s).substr(pos, len), td::MutableSlice(t).substr(pos, len)); pos += len; @@ -132,7 +132,7 @@ TEST(Crypto, AesIgeState) { td::UInt256 iv_copy = iv; td::string u(length, '\0'); std::size_t pos = 0; - for (auto str : td::rand_split(td::string(length / 16, '\0'))) { + for (const auto &str : td::rand_split(td::string(length / 16, '\0'))) { auto len = 16 * str.size(); state.encrypt(td::Slice(s).substr(pos, len), td::MutableSlice(t).substr(pos, len)); td::aes_ige_encrypt(as_slice(key), as_slice(iv_copy), td::Slice(s).substr(pos, len), @@ -146,7 +146,7 @@ TEST(Crypto, AesIgeState) { state.init(as_slice(key), as_slice(iv), false); iv_copy = iv; pos = 0; - for (auto str : td::rand_split(td::string(length / 16, '\0'))) { + for (const auto &str : td::rand_split(td::string(length / 16, '\0'))) { auto len = 16 * str.size(); state.decrypt(td::Slice(t).substr(pos, len), td::MutableSlice(t).substr(pos, len)); td::aes_ige_decrypt(as_slice(key), as_slice(iv_copy), td::Slice(u).substr(pos, len), @@ -188,7 +188,7 @@ TEST(Crypto, AesCbcState) { td::UInt128 iv_copy = iv; td::string u(length, '\0'); std::size_t pos = 0; - for (auto str : td::rand_split(td::string(length / 16, '\0'))) { + for (const auto &str : td::rand_split(td::string(length / 16, '\0'))) { auto len = 16 * str.size(); state.encrypt(td::Slice(s).substr(pos, len), td::MutableSlice(t).substr(pos, len)); td::aes_cbc_encrypt(as_slice(key), as_slice(iv_copy), td::Slice(s).substr(pos, len), @@ -202,7 +202,7 @@ TEST(Crypto, AesCbcState) { state = td::AesCbcState(as_slice(key), as_slice(iv)); iv_copy = iv; pos = 0; - for (auto str : td::rand_split(td::string(length / 16, '\0'))) { + for (const auto &str : td::rand_split(td::string(length / 16, '\0'))) { auto len = 16 * str.size(); state.decrypt(td::Slice(t).substr(pos, len), td::MutableSlice(t).substr(pos, len)); td::aes_cbc_decrypt(as_slice(key), as_slice(iv_copy), td::Slice(u).substr(pos, len), diff --git a/tdutils/test/gzip.cpp b/tdutils/test/gzip.cpp index 6486dfa2e..9759626ee 100644 --- a/tdutils/test/gzip.cpp +++ b/tdutils/test/gzip.cpp @@ -18,7 +18,7 @@ #include -static void encode_decode(td::string s) { +static void encode_decode(const td::string &s) { auto r = td::gzencode(s, 2); ASSERT_TRUE(!r.empty()); ASSERT_EQ(s, td::gzdecode(r.as_slice())); @@ -30,7 +30,7 @@ TEST(Gzip, gzencode_gzdecode) { encode_decode(td::string(1000000, 'a')); } -static void test_gzencode(td::string s) { +static void test_gzencode(const td::string &s) { auto begin_time = td::Time::now(); auto r = td::gzencode(s, td::max(2, static_cast(100 / s.size()))); ASSERT_TRUE(!r.empty()); diff --git a/tdutils/test/json.cpp b/tdutils/test/json.cpp index f374a233d..df0f4a0a6 100644 --- a/tdutils/test/json.cpp +++ b/tdutils/test/json.cpp @@ -12,7 +12,7 @@ #include -static void decode_encode(td::string str, td::string result = "") { +static void decode_encode(const td::string &str, td::string result = td::string()) { auto str_copy = str; auto r_value = td::json_decode(str_copy); ASSERT_TRUE(r_value.is_ok()); diff --git a/tdutils/test/log.cpp b/tdutils/test/log.cpp index e09d565ee..93505440b 100644 --- a/tdutils/test/log.cpp +++ b/tdutils/test/log.cpp @@ -43,7 +43,7 @@ class LogBenchmark final : public td::Benchmark { threads_.resize(threads_n_); } void tear_down() final { - for (auto path : log_->get_file_paths()) { + for (const auto &path : log_->get_file_paths()) { td::unlink(path).ignore(); } log_.reset(); diff --git a/tdutils/test/misc.cpp b/tdutils/test/misc.cpp index a5474e588..d822f7244 100644 --- a/tdutils/test/misc.cpp +++ b/tdutils/test/misc.cpp @@ -266,7 +266,7 @@ TEST(Misc, base64) { } template -static void test_remove_if(td::vector v, const T &func, td::vector expected) { +static void test_remove_if(td::vector v, const T &func, const td::vector &expected) { td::remove_if(v, func); if (expected != v) { LOG(FATAL) << "Receive " << v << ", expected " << expected << " in remove_if"; @@ -324,7 +324,7 @@ TEST(Misc, remove_if) { test_remove_if(v, none, v); } -static void test_remove(td::vector v, int value, td::vector expected) { +static void test_remove(td::vector v, int value, const td::vector &expected) { bool is_found = expected != v; ASSERT_EQ(is_found, td::remove(v, value)); if (expected != v) { @@ -349,7 +349,7 @@ TEST(Misc, remove) { test_remove(v, 1, v); } -static void test_unique(td::vector v, td::vector expected) { +static void test_unique(td::vector v, const td::vector &expected) { auto v_str = td::transform(v, &td::to_string); auto expected_str = td::transform(expected, &td::to_string); @@ -516,7 +516,7 @@ TEST(Misc, print_uint) { ASSERT_STREQ("9223372036854775807", PSLICE() << 9223372036854775807u); } -static void test_idn_to_ascii_one(td::string host, td::string result) { +static void test_idn_to_ascii_one(const td::string &host, const td::string &result) { if (result != td::idn_to_ascii(host).ok()) { LOG(ERROR) << "Failed to convert " << host << " to " << result << ", got \"" << td::idn_to_ascii(host).ok() << "\""; } @@ -557,7 +557,7 @@ TEST(Misc, idn_to_ascii) { } #if TD_WINDOWS -static void test_to_wstring_one(td::string str) { +static void test_to_wstring_one(const td::string &str) { ASSERT_STREQ(str, td::from_wstring(td::to_wstring(str).ok()).ok()); } @@ -589,7 +589,7 @@ TEST(Misc, to_wstring) { } #endif -static void test_translit(td::string word, td::vector result, bool allow_partial = true) { +static void test_translit(const td::string &word, const td::vector &result, bool allow_partial = true) { ASSERT_EQ(result, td::get_word_transliterations(word, allow_partial)); } @@ -679,7 +679,7 @@ TEST(Misc, IPAddress_get_ipv4) { test_get_ipv4(0xFFFFFFFF); } -static void test_is_reserved(td::string ip, bool is_reserved) { +static void test_is_reserved(const td::string &ip, bool is_reserved) { td::IPAddress ip_address; ip_address.init_ipv4_port(ip, 80).ensure(); ASSERT_EQ(is_reserved, ip_address.is_reserved()); @@ -772,11 +772,11 @@ TEST(Misc, split) { test_split(" abcdef ", {"", "abcdef "}); } -static void test_full_split(td::Slice str, td::vector expected) { +static void test_full_split(td::Slice str, const td::vector &expected) { ASSERT_EQ(expected, td::full_split(str)); } -static void test_full_split(td::Slice str, char c, std::size_t max_parts, td::vector expected) { +static void test_full_split(td::Slice str, char c, std::size_t max_parts, const td::vector &expected) { ASSERT_EQ(expected, td::full_split(str, c, max_parts)); } @@ -804,11 +804,12 @@ TEST(Misc, StringBuilder) { using V = td::vector; for (auto use_buf : {false, true}) { for (std::size_t initial_buffer_size : {0, 1, 5, 10, 100, 1000, 2000}) { - for (auto test : {V{small_str}, V{small_str, big_str, big_str, small_str}, V{big_str, small_str, big_str}}) { + for (const auto &test : + {V{small_str}, V{small_str, big_str, big_str, small_str}, V{big_str, small_str, big_str}}) { td::string buf(initial_buffer_size, '\0'); td::StringBuilder sb(buf, use_buf); td::string res; - for (auto x : test) { + for (const auto &x : test) { res += x; sb << x; } @@ -1046,9 +1047,11 @@ TEST(Misc, uint128) { if (b == 0) { continue; } - td::int64 q, r; + td::int64 q; + td::int64 r; a.divmod_signed(b, &q, &r); - td::int64 iq, ir; + td::int64 iq; + td::int64 ir; ia.divmod_signed(b, &iq, &ir); ASSERT_EQ(q, iq); ASSERT_EQ(r, ir); diff --git a/tdutils/test/pq.cpp b/tdutils/test/pq.cpp index 9c0d18555..a12ecf307 100644 --- a/tdutils/test/pq.cpp +++ b/tdutils/test/pq.cpp @@ -77,7 +77,8 @@ static void test_pq(td::uint64 first, td::uint64 second) { td::BigNum::mul(pq, p, q, context); td::string pq_str = pq.to_binary(); - td::string p_str, q_str; + td::string p_str; + td::string q_str; int err = td::pq_factorize(pq_str, &p_str, &q_str); LOG_CHECK(err == 0) << first << " * " << second; diff --git a/test/db.cpp b/test/db.cpp index b3970af62..b48903950 100644 --- a/test/db.cpp +++ b/test/db.cpp @@ -322,14 +322,14 @@ class SqliteKV { class BaselineKV { public: - string get(string key) { + string get(const string &key) { return map_[key]; } - SeqNo set(string key, string value) { - map_[key] = value; + SeqNo set(const string &key, string value) { + map_[key] = std::move(value); return ++current_tid_; } - SeqNo erase(string key) { + SeqNo erase(const string &key) { map_.erase(key); return ++current_tid_; } diff --git a/test/http.cpp b/test/http.cpp index 26c9d0c84..3696ea2cb 100644 --- a/test/http.cpp +++ b/test/http.cpp @@ -48,7 +48,7 @@ using namespace td; -static string make_chunked(string str) { +static string make_chunked(const string &str) { auto v = rand_split(str); string res; for (auto &s : v) { @@ -75,7 +75,7 @@ static string gen_http_content() { } static string make_http_query(string content, bool is_json, bool is_chunked, bool is_gzip, double gzip_k = 5, - string zip_override = "") { + string zip_override = string()) { HttpHeaderCreator hc; hc.init_post("/"); hc.add_header("jfkdlsahhjk", rand_string('a', 'z', Random::fast(1, 2000))); diff --git a/test/link.cpp b/test/link.cpp index 5f7d0cb57..2af303cce 100644 --- a/test/link.cpp +++ b/test/link.cpp @@ -13,7 +13,7 @@ #include "td/utils/misc.h" #include "td/utils/tests.h" -static void check_find_urls(td::string url, bool is_valid) { +static void check_find_urls(const td::string &url, bool is_valid) { auto url_lower = td::to_lower(url); { auto tg_urls = td::find_tg_urls(url); @@ -35,7 +35,7 @@ static void check_find_urls(td::string url, bool is_valid) { } } -static void check_link(td::string url, td::string expected) { +static void check_link(const td::string &url, const td::string &expected) { auto result = td::LinkManager::check_link(url); if (result.is_ok()) { ASSERT_STREQ(expected, result.ok()); @@ -79,7 +79,7 @@ TEST(Link, check_link) { check_link("https://.", ""); } -static void parse_internal_link(td::string url, td::td_api::object_ptr expected) { +static void parse_internal_link(const td::string &url, td::td_api::object_ptr expected) { auto result = td::LinkManager::parse_internal_link(url); if (result != nullptr) { auto object = result->get_internal_link_type_object(); diff --git a/test/message_entities.cpp b/test/message_entities.cpp index d2a1dbefc..de37c75db 100644 --- a/test/message_entities.cpp +++ b/test/message_entities.cpp @@ -1745,8 +1745,8 @@ TEST(MessageEntities, parse_markdown_v3) { } } -static void check_get_markdown_v3(td::string result_text, td::vector result_entities, - const td::string &text, const td::vector &entities) { +static void check_get_markdown_v3(const td::string &result_text, const td::vector &result_entities, + td::string text, td::vector entities) { auto markdown_text = td::get_markdown_v3({std::move(text), std::move(entities)}); ASSERT_STREQ(result_text, markdown_text.text); ASSERT_EQ(result_entities, markdown_text.entities); diff --git a/test/mtproto.cpp b/test/mtproto.cpp index 7bee6b377..d30b0b2d4 100644 --- a/test/mtproto.cpp +++ b/test/mtproto.cpp @@ -95,11 +95,11 @@ TEST(Mtproto, GetHostByNameActor) { "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "[2001:0db8:85a3:0000:0000:8a2e:0370:7334]", "[[2001:0db8:85a3:0000:0000:8a2e:0370:7334]]"}; - for (auto types : {vector{GetHostByNameActor::ResolverType::Native}, - vector{GetHostByNameActor::ResolverType::Google}, - vector{GetHostByNameActor::ResolverType::Google, - GetHostByNameActor::ResolverType::Google, - GetHostByNameActor::ResolverType::Native}}) { + for (const auto &types : {vector{GetHostByNameActor::ResolverType::Native}, + vector{GetHostByNameActor::ResolverType::Google}, + vector{GetHostByNameActor::ResolverType::Google, + GetHostByNameActor::ResolverType::Google, + GetHostByNameActor::ResolverType::Native}}) { GetHostByNameActor::Options options; options.resolver_types = types; options.scheduler_id = threads_n; diff --git a/test/poll.cpp b/test/poll.cpp index 3bd5a88a0..b1b4f6503 100644 --- a/test/poll.cpp +++ b/test/poll.cpp @@ -9,8 +9,8 @@ #include "td/utils/logging.h" #include "td/utils/tests.h" -static void check_vote_percentage(std::vector voter_counts, td::int32 total_count, - std::vector expected) { +static void check_vote_percentage(const std::vector &voter_counts, td::int32 total_count, + const std::vector &expected) { auto result = td::PollManager::get_vote_percentage(voter_counts, total_count); if (result != expected) { LOG(FATAL) << "Have " << voter_counts << " and " << total_count << ", but received " << result << " instead of " diff --git a/test/secret.cpp b/test/secret.cpp index 3bffb0f88..5dd40afb3 100644 --- a/test/secret.cpp +++ b/test/secret.cpp @@ -764,15 +764,17 @@ class Master final : public Actor { bob_ = create_actor("SecretChatProxy bob", "bob", actor_shared(this, 2)); send_closure(alice_->get_actor_unsafe()->actor_, &SecretChatActor::create_chat, UserId(static_cast(2)), 0, 123, PromiseCreator::lambda([actor_id = actor_id(this)](Result res) { - send_closure(actor_id, &Master::got_secret_chat_id, std::move(res), 0); + send_closure(actor_id, &Master::got_secret_chat_id, std::move(res), false); })); } - void got_secret_chat_id(Result res, int) { // second parameter is needed to workaround clang bug + + void got_secret_chat_id(Result res, bool dummy) { CHECK(res.is_ok()); auto id = res.move_as_ok(); LOG(INFO) << "SecretChatId = " << id; } - bool can_fail(NetQueryPtr &query) { + + static bool can_fail(NetQueryPtr &query) { static int cnt = 20; if (cnt > 0) { cnt--; @@ -784,6 +786,7 @@ class Master final : public Actor { } return false; } + void send_net_query(NetQueryPtr query, ActorShared callback, bool ordered) { if (can_fail(query) && Random::fast_bool()) { LOG(INFO) << "Fail query " << query; diff --git a/test/string_cleaning.cpp b/test/string_cleaning.cpp index 0b60b825d..6e98f1b02 100644 --- a/test/string_cleaning.cpp +++ b/test/string_cleaning.cpp @@ -36,7 +36,7 @@ TEST(StringCleaning, clean_username) { ASSERT_EQ("asd", clean_username(". ASD ..")); } -static void check_clean_input_string(string str, string expected, bool expected_result) { +static void check_clean_input_string(string str, const string &expected, bool expected_result) { auto result = clean_input_string(str); ASSERT_EQ(expected_result, result); if (result) { @@ -73,8 +73,9 @@ TEST(StringCleaning, clean_input_string) { check_clean_input_string("\xcc\xb3\xcc\xbf\xcc\x8a", "", true); } -static void check_strip_empty_characters(string str, size_t max_length, string expected, bool strip_rtlo = false) { - ASSERT_EQ(expected, strip_empty_characters(str, max_length, strip_rtlo)); +static void check_strip_empty_characters(string str, size_t max_length, const string &expected, + bool strip_rtlo = false) { + ASSERT_EQ(expected, strip_empty_characters(std::move(str), max_length, strip_rtlo)); } TEST(StringCleaning, strip_empty_characters) { diff --git a/test/tdclient.cpp b/test/tdclient.cpp index 3d9a2fe69..72363bc84 100644 --- a/test/tdclient.cpp +++ b/test/tdclient.cpp @@ -568,7 +568,8 @@ class TestFileGenerated final : public TestClinetTask { } }; - void generate_file(td::int64 id, td::string original_path, td::string destination_path, td::string conversion) { + void generate_file(td::int64 id, const td::string &original_path, const td::string &destination_path, + const td::string &conversion) { LOG(ERROR) << "Generate file " << td::tag("id", id) << td::tag("original_path", original_path) << td::tag("destination_path", destination_path) << td::tag("conversion", conversion); if (conversion == "square") { diff --git a/test/tqueue.cpp b/test/tqueue.cpp index 37845b592..29b471e83 100644 --- a/test/tqueue.cpp +++ b/test/tqueue.cpp @@ -100,7 +100,7 @@ class TestTQueue { } } - EventId push(td::TQueue::QueueId queue_id, td::string data, td::int32 expires_at, EventId new_id = EventId()) { + EventId push(td::TQueue::QueueId queue_id, const td::string &data, td::int32 expires_at, EventId new_id = EventId()) { auto a_id = baseline_->push(queue_id, data, expires_at, 0, new_id).move_as_ok(); auto b_id = memory_->push(queue_id, data, expires_at, 0, new_id).move_as_ok(); auto c_id = binlog_->push(queue_id, data, expires_at, 0, new_id).move_as_ok();