Merge remote-tracking branch 'td/master'

This commit is contained in:
Andrea Cavalli 2021-10-21 17:09:27 +02:00
commit f11254bdcb
69 changed files with 177 additions and 174 deletions

View File

@ -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"

View File

@ -4218,7 +4218,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
@ -4746,7 +4746,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<int53> = 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;

View File

@ -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<const tl::tl_tree_type *>(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<tl::tl_tree_type *>(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);

View File

@ -13,6 +13,7 @@
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Slice.h"
namespace td {
namespace mtproto {

View File

@ -453,9 +453,10 @@ class RawConnectionHttp final : public RawConnection {
unique_ptr<RawConnection> RawConnection::create(IPAddress ip_address, SocketFd socket_fd, TransportType transport_type,
unique_ptr<StatsCallback> stats_callback) {
#if TD_DARWIN_WATCH_OS
return td::make_unique<RawConnectionHttp>(ip_address, std::move(stats_callback));
return td::make_unique<RawConnectionHttp>(std::move(ip_address), std::move(stats_callback));
#else
return td::make_unique<RawConnectionDefault>(std::move(socket_fd), transport_type, std::move(stats_callback));
return td::make_unique<RawConnectionDefault>(std::move(socket_fd), std::move(transport_type),
std::move(stats_callback));
#endif
}

View File

@ -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 {

View File

@ -19,8 +19,6 @@
#include "td/utils/buffer.h"
#include "td/utils/common.h"
#include <unordered_map>
namespace td {
class Td;

View File

@ -16,7 +16,7 @@ namespace td {
ClientActor::ClientActor(unique_ptr<TdCallback> 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>("Td", std::move(callback), std::move(td_options));
}

View File

@ -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"

View File

@ -1310,17 +1310,17 @@ class ContactsManager final : public Actor {
void load_secret_chat_from_database_impl(SecretChatId secret_chat_id, Promise<Unit> 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);

View File

@ -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<NetQueryCallback> callback) {

View File

@ -13,7 +13,6 @@
#include "td/utils/common.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"
#include <limits>

View File

@ -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"

View File

@ -16,6 +16,7 @@
#include "td/telegram/StickersManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/Td.h"
#include "td/telegram/WebPageId.h"
#include "td/telegram/WebPagesManager.h"
#include "td/utils/algorithm.h"

View File

@ -11,6 +11,7 @@
#include "td/telegram/ConfigManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/DialogAction.h"
#include "td/telegram/Global.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/MemoryManager.h"

View File

@ -4008,6 +4008,8 @@ unique_ptr<MessageContent> 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";

View File

@ -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 <utility>

View File

@ -34,6 +34,7 @@
#include <array>
#include <iterator>
#include <limits>
#include <tuple>
#include <utility>
namespace td {
@ -850,8 +851,9 @@ class MessagesDbImpl final : public MessagesDbSyncInterface {
SqliteStatement delete_scheduled_message_stmt_;
SqliteStatement delete_scheduled_server_message_stmt_;
Result<vector<MessagesDbDialogMessage>> get_messages_impl(GetMessagesStmt &stmt, DialogId dialog_id,
MessageId from_message_id, int32 offset, int32 limit) {
static Result<vector<MessagesDbDialogMessage>> 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());

View File

@ -18262,7 +18262,7 @@ void MessagesManager::on_reorder_dialog_filters(vector<DialogFilterId> 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();
}
}

View File

@ -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"
@ -1818,7 +1819,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<int32> &&result);
int32 schedule_date, uint64 generation, Result<int32> &&result);
static MessageId get_persistent_message_id(const Dialog *d, MessageId message_id);

View File

@ -6643,7 +6643,7 @@ string StickersManager::get_language_emojis_database_key(const string &language_
}
vector<string> 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) {

View File

@ -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"
@ -660,7 +661,7 @@ class StickersManager final : public Actor {
void on_get_language_codes(const string &key, Result<vector<string>> &&result);
vector<string> search_language_emojis(const string &language_code, const string &text, bool exact_match) const;
static vector<string> search_language_emojis(const string &language_code, const string &text, bool exact_match);
void load_emoji_keywords(const string &language_code, Promise<Unit> &&promise);

View File

@ -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"

View File

@ -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"
@ -171,7 +170,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 {

View File

@ -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 {

View File

@ -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;

View File

@ -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 <array>
@ -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<vector<DialogId>> promise;
};
std::vector<GetTopDialogsQuery> pending_get_top_dialogs_;
vector<GetTopDialogsQuery> 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<TopDialog> dialogs;
vector<TopDialog> dialogs;
};
template <class StorerT>
friend void store(const TopDialog &top_dialog, StorerT &storer);

View File

@ -1831,7 +1831,7 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::setPassportElement>(
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<td_api::deletePassportElement>(as_passport_element_type(passport_element_type)));
} else if (op == "ppn") {
send_request(td_api::make_object<td_api::processPushNotification>(args));
@ -1951,7 +1951,7 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::addContact>(
td_api::make_object<td_api::contact>(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<td_api::sharePhoneNumber>(as_user_id(user_id)));
} else if (op == "ImportContacts" || op == "cic") {
vector<string> contacts_str = full_split(args, ';');
@ -2013,7 +2013,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<td_api::getChatScheduledMessages>(as_chat_id(chat_id)));
} else if (op == "gmpf") {
string chat_id;
@ -2142,10 +2142,10 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::getLanguagePackString>(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<td_api::synchronizeLanguagePack>(language_code));
} else if (op == "acslp") {
string language_code = std::move(args);
const string &language_code = args;
send_request(td_api::make_object<td_api::addCustomServerLanguagePack>(language_code));
} else if (op == "sclp") {
string language_code;
@ -2441,10 +2441,10 @@ class CliClient final : public Actor {
get_args(args, chat_id, category);
send_request(td_api::make_object<td_api::removeTopChat>(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<td_api::getSuggestedStickerSetName>(title));
} else if (op == "cssn") {
string name = std::move(args);
const string &name = args;
send_request(td_api::make_object<td_api::checkStickerSetName>(name));
} else if (op == "usf" || op == "usfa") {
td_api::object_ptr<td_api::InputSticker> input_sticker;
@ -2554,7 +2554,7 @@ class CliClient final : public Actor {
get_args(args, chat_id, member_id);
send_request(td_api::make_object<td_api::getChatMember>(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<td_api::getChatAdministrators>(as_chat_id(chat_id)));
} else if (op == "GetSupergroupAdministrators" || op == "GetSupergroupBanned" || op == "GetSupergroupBots" ||
op == "GetSupergroupContacts" || op == "GetSupergroupMembers" || op == "GetSupergroupRestricted" ||
@ -2610,7 +2610,7 @@ class CliClient final : public Actor {
get_args(args, chat_id, message_id);
send_request(td_api::make_object<td_api::getMessageViewers>(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<td_api::getChatPinnedMessage>(as_chat_id(chat_id)));
} else if (op == "gms") {
string chat_id;
@ -2720,7 +2720,7 @@ class CliClient final : public Actor {
} else if (op == "cuf") {
send_request(td_api::make_object<td_api::cancelUploadFile>(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<td_api::deleteFile>(as_file_id(file_id)));
} else if (op == "dm" || op == "dmr") {
string chat_id;
@ -2850,7 +2850,7 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::toggleGroupCallScreenSharingIsPaused>(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<td_api::endGroupCallScreenSharing>(as_group_call_id(group_call_id)));
} else if (op == "sgct") {
string chat_id;
@ -2902,7 +2902,7 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::startGroupCallRecording>(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<td_api::endGroupCallRecording>(as_group_call_id(chat_id)));
} else if (op == "tgcpim") {
string group_call_id;
@ -2936,7 +2936,7 @@ class CliClient final : public Actor {
} else if (op == "dgc") {
send_request(td_api::make_object<td_api::discardGroupCall>(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<td_api::replacePrimaryChatInviteLink>(as_chat_id(chat_id)));
} else if (op == "ccilt") {
string chat_id;
@ -2958,7 +2958,7 @@ class CliClient final : public Actor {
get_args(args, chat_id, invite_link);
send_request(td_api::make_object<td_api::revokeChatInviteLink>(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<td_api::getChatInviteLinkCounts>(as_chat_id(chat_id)));
} else if (op == "gcil") {
string chat_id;
@ -3734,10 +3734,10 @@ class CliClient final : public Actor {
get_args(args, supergroup_id, force);
send_request(td_api::make_object<td_api::createSupergroupChat>(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<td_api::getChatListsToAddChat>(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<td_api::addChatToList>(as_chat_id(chat_id), as_chat_list(op)));
} else if (op == "gcf") {
send_request(td_api::make_object<td_api::getChatFilter>(as_chat_filter_id(args)));
@ -3768,7 +3768,7 @@ class CliClient final : public Actor {
get_args(args, chat_id, title);
send_request(td_api::make_object<td_api::setChatTitle>(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<td_api::setChatPhoto>(as_chat_id(chat_id), nullptr));
} else if (op == "scpp") {
string chat_id;
@ -4033,7 +4033,7 @@ class CliClient final : public Actor {
get_args(args, chat_id, message_id);
send_request(td_api::make_object<td_api::unpinChatMessage>(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<td_api::unpinAllChatMessages>(as_chat_id(chat_id)));
} else if (op == "grib") {
send_request(td_api::make_object<td_api::getRecentInlineBots>());
@ -4091,10 +4091,10 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::setProfilePhoto>(td_api::make_object<td_api::inputChatPhotoAnimation>(
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<td_api::searchHashtags>(prefix, 10));
} else if (op == "rrh") {
auto hashtag = std::move(args);
const string &hashtag = args;
send_request(td_api::make_object<td_api::removeRecentHashtag>(hashtag));
} else if (op == "view" || op == "viewt") {
string chat_id;
@ -4118,16 +4118,16 @@ class CliClient final : public Actor {
send_request(
td_api::make_object<td_api::clickAnimatedEmojiMessage>(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<td_api::getInternalLinkType>(link));
} else if (op == "geli") {
string link = std::move(args);
const string &link = args;
send_request(td_api::make_object<td_api::getExternalLinkInfo>(link));
} else if (op == "gel" || op == "gelw") {
string link = std::move(args);
const string &link = args;
send_request(td_api::make_object<td_api::getExternalLink>(link, op == "gelw"));
} else if (op == "racm") {
string chat_id = std::move(args);
const string &chat_id = args;
send_request(td_api::make_object<td_api::readAllChatMentions>(as_chat_id(chat_id)));
} else if (op == "tre") {
send_request(td_api::make_object<td_api::testReturnError>(
@ -4178,7 +4178,7 @@ class CliClient final : public Actor {
get_args(args, group_id, max_notification_id);
send_request(td_api::make_object<td_api::removeNotificationGroup>(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<td_api::removeChatActionBar>(as_chat_id(chat_id)));
} else if (op == "rc") {
string chat_id;
@ -4357,7 +4357,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<td_api::getLogTagVerbosityLevel>(tag);
if (op == "gltvl") {
send_request(std::move(request));

View File

@ -139,7 +139,7 @@ class FileDb final : public FileDbInterface {
pmc.commit_transaction().ensure();
}
void optimize_refs(const std::vector<FileDbId> ids, FileDbId main_id) {
void optimize_refs(std::vector<FileDbId> 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();

View File

@ -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 <algorithm>

View File

@ -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"

View File

@ -7,7 +7,6 @@
#pragma once
#include "td/utils/common.h"
#include "td/utils/Slice.h"
namespace td {

View File

@ -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);

View File

@ -34,7 +34,7 @@ EMSCRIPTEN_KEEPALIVE double td_emscripten_get_timeout() {
}
}
int main(void) {
int main() {
emscripten_exit_with_live_runtime();
return 0;
}

View File

@ -35,7 +35,7 @@ class MainActor final : public td::Actor {
td::ActorOwn<Worker> worker_;
};
int main(void) {
int main() {
td::ConcurrentScheduler scheduler;
scheduler.init(4 /*threads_count*/);
scheduler.start();

View File

@ -407,10 +407,10 @@ class CancellablePromise final : public PromiseT {
CancellablePromise(CancellationToken cancellation_token, ArgsT &&... args)
: PromiseT(std::forward<ArgsT>(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<bool>(cancellation_token_);
}

View File

@ -50,9 +50,9 @@ TEST(MultiTimeout, bug) {
}
class TimeoutManager final : public td::Actor {
public:
static td::int32 count;
public:
TimeoutManager() {
count++;

View File

@ -19,8 +19,6 @@
#include <memory>
#include <utility>
namespace {
template <class ContainerT>
static typename ContainerT::value_type &rand_elem(ContainerT &cont) {
CHECK(0 < cont.size() && cont.size() <= static_cast<size_t>(std::numeric_limits<int>::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;

View File

@ -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 <memory>
#include <tuple>
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>("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<DelayedCall> delayed_call_;
};

View File

@ -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);

View File

@ -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 {

View File

@ -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 {

View File

@ -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;

View File

@ -26,7 +26,7 @@ class EventFdLinux final : public EventFdBase {
EventFdLinux();
EventFdLinux(EventFdLinux &&) noexcept;
EventFdLinux &operator=(EventFdLinux &&) noexcept;
~EventFdLinux() override;
~EventFdLinux() final;
void init() final;

View File

@ -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<int64>(signed_value() / y);
*rem = static_cast<int64>(signed_value() % y);
}
private:

View File

@ -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 {

View File

@ -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 {

View File

@ -110,7 +110,8 @@ static void do_run_list_test(ListRootT &root, std::atomic<td::uint64> &id) {
nodes[i] = std::move(nodes[j]);
};
auto validate = [&] {
std::multiset<td::uint64> in_list, not_in_list;
std::multiset<td::uint64> in_list;
std::multiset<td::uint64> not_in_list;
for (auto &node : nodes) {
if (get_data(node).in_list.get()) {
in_list.insert(get_data(node).value.get());

View File

@ -50,7 +50,7 @@ TEST(OneValue, stress) {
std::vector<td::thread> threads;
td::OneValue<std::string> 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();

View File

@ -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) {

View File

@ -17,7 +17,7 @@ TEST(OptionParser, run) {
td::string exename = "exename";
td::vector<td::string> 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<char *> argv;
argv.push_back(&exename[0]);
for (auto &arg : args) {
@ -29,10 +29,11 @@ TEST(OptionParser, run) {
td::uint64 chosen_options = 0;
td::vector<td::string> chosen_parameters;
auto test_success = [&](td::string command_line, td::uint64 expected_options,
td::vector<td::string> expected_parameters, td::vector<td::string> expected_result) {
const td::vector<td::string> &expected_parameters,
const td::vector<td::string> &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());
};

View File

@ -19,7 +19,7 @@ TEST(OrderedEventsProcessor, random) {
std::vector<std::pair<int, int>> 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());

View File

@ -61,7 +61,8 @@ TEST(SharedSlice, Hands) {
{
td::Stage stage;
td::SharedSlice a, b;
td::SharedSlice a;
td::SharedSlice b;
td::vector<td::thread> threads(2);
for (int i = 0; i < 2; i++) {
threads[i] = td::thread([i, &stage, &a, &b] {

View File

@ -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),

View File

@ -18,7 +18,7 @@
#include <algorithm>
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<int>(100 / s.size())));
ASSERT_TRUE(!r.empty());

View File

@ -12,7 +12,7 @@
#include <utility>
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());

View File

@ -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();

View File

@ -266,7 +266,7 @@ TEST(Misc, base64) {
}
template <class T>
static void test_remove_if(td::vector<int> v, const T &func, td::vector<int> expected) {
static void test_remove_if(td::vector<int> v, const T &func, const td::vector<int> &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<int> v, int value, td::vector<int> expected) {
static void test_remove(td::vector<int> v, int value, const td::vector<int> &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<int> v, td::vector<int> expected) {
static void test_unique(td::vector<int> v, const td::vector<int> &expected) {
auto v_str = td::transform(v, &td::to_string<int>);
auto expected_str = td::transform(expected, &td::to_string<int>);
@ -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<td::string> result, bool allow_partial = true) {
static void test_translit(const td::string &word, const td::vector<td::string> &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<td::Slice> expected) {
static void test_full_split(td::Slice str, const td::vector<td::Slice> &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<td::Slice> expected) {
static void test_full_split(td::Slice str, char c, std::size_t max_parts, const td::vector<td::Slice> &expected) {
ASSERT_EQ(expected, td::full_split(str, c, max_parts));
}
@ -804,11 +804,12 @@ TEST(Misc, StringBuilder) {
using V = td::vector<td::string>;
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);

View File

@ -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;

View File

@ -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_;
}

View File

@ -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)));

View File

@ -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<td::td_api::InternalLinkType> expected) {
static void parse_internal_link(const td::string &url, td::td_api::object_ptr<td::td_api::InternalLinkType> expected) {
auto result = td::LinkManager::parse_internal_link(url);
if (result != nullptr) {
auto object = result->get_internal_link_type_object();

View File

@ -1745,8 +1745,8 @@ TEST(MessageEntities, parse_markdown_v3) {
}
}
static void check_get_markdown_v3(td::string result_text, td::vector<td::MessageEntity> result_entities,
const td::string &text, const td::vector<td::MessageEntity> &entities) {
static void check_get_markdown_v3(const td::string &result_text, const td::vector<td::MessageEntity> &result_entities,
td::string text, td::vector<td::MessageEntity> 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);

View File

@ -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>{GetHostByNameActor::ResolverType::Native},
vector<GetHostByNameActor::ResolverType>{GetHostByNameActor::ResolverType::Google},
vector<GetHostByNameActor::ResolverType>{GetHostByNameActor::ResolverType::Google,
GetHostByNameActor::ResolverType::Google,
GetHostByNameActor::ResolverType::Native}}) {
for (const auto &types : {vector<GetHostByNameActor::ResolverType>{GetHostByNameActor::ResolverType::Native},
vector<GetHostByNameActor::ResolverType>{GetHostByNameActor::ResolverType::Google},
vector<GetHostByNameActor::ResolverType>{GetHostByNameActor::ResolverType::Google,
GetHostByNameActor::ResolverType::Google,
GetHostByNameActor::ResolverType::Native}}) {
GetHostByNameActor::Options options;
options.resolver_types = types;
options.scheduler_id = threads_n;

View File

@ -9,8 +9,8 @@
#include "td/utils/logging.h"
#include "td/utils/tests.h"
static void check_vote_percentage(std::vector<td::int32> voter_counts, td::int32 total_count,
std::vector<td::int32> expected) {
static void check_vote_percentage(const std::vector<td::int32> &voter_counts, td::int32 total_count,
const std::vector<td::int32> &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 "

View File

@ -764,15 +764,17 @@ class Master final : public Actor {
bob_ = create_actor<SecretChatProxy>("SecretChatProxy bob", "bob", actor_shared(this, 2));
send_closure(alice_->get_actor_unsafe()->actor_, &SecretChatActor::create_chat, UserId(static_cast<int64>(2)), 0,
123, PromiseCreator::lambda([actor_id = actor_id(this)](Result<SecretChatId> 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<SecretChatId> res, int) { // second parameter is needed to workaround clang bug
void got_secret_chat_id(Result<SecretChatId> 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<NetQueryCallback> callback, bool ordered) {
if (can_fail(query) && Random::fast_bool()) {
LOG(INFO) << "Fail query " << query;

View File

@ -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) {

View File

@ -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") {

View File

@ -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();