Skip to content

Commit db7aa28

Browse files
committed
A lot more minor improvements.
1 parent 44a186c commit db7aa28

114 files changed

Lines changed: 1023 additions & 965 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎benchmark/bench_misc.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ BENCH(NewObj, "new struct, then delete") {
105105

106106
#if !TD_THREAD_UNSUPPORTED
107107
BENCH(ThreadNew, "new struct, then delete in 2 threads") {
108-
NewObjBench a, b;
108+
NewObjBench a;
109+
NewObjBench b;
109110
td::thread ta([&] { a.run(n / 2); });
110111
td::thread tb([&] { b.run(n - n / 2); });
111112
ta.join();

‎td/telegram/AuthManager.cpp‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void AuthManager::check_bot_token(uint64 query_id, string bot_token) {
162162
}
163163

164164
on_new_query(query_id);
165-
bot_token_ = bot_token;
165+
bot_token_ = std::move(bot_token);
166166
was_check_bot_token_ = true;
167167
start_net_query(NetQueryType::BotAuthentication,
168168
G()->net_query_creator().create_unauth(
@@ -258,8 +258,8 @@ void AuthManager::set_phone_number(uint64 query_id, string phone_number,
258258

259259
on_new_query(query_id);
260260

261-
start_net_query(NetQueryType::SendCode, G()->net_query_creator().create_unauth(
262-
send_code_helper_.send_code(phone_number, settings, api_id_, api_hash_)));
261+
start_net_query(NetQueryType::SendCode, G()->net_query_creator().create_unauth(send_code_helper_.send_code(
262+
std::move(phone_number), settings, api_id_, api_hash_)));
263263
}
264264

265265
void AuthManager::resend_authentication_code(uint64 query_id) {
@@ -425,8 +425,8 @@ void AuthManager::on_query_error(Status status) {
425425
on_query_error(id, std::move(status));
426426
}
427427

428-
void AuthManager::on_query_error(uint64 id, Status status) {
429-
send_closure(G()->td(), &Td::send_error, id, std::move(status));
428+
void AuthManager::on_query_error(uint64 query_id, Status status) {
429+
send_closure(G()->td(), &Td::send_error, query_id, std::move(status));
430430
}
431431

432432
void AuthManager::on_query_ok() {

‎td/telegram/AuthManager.h‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,30 +126,31 @@ class AuthManager final : public NetActor {
126126
TermsOfService terms_of_service_;
127127

128128
DbState() = default;
129+
129130
static DbState wait_code(int32 api_id, string api_hash, SendCodeHelper send_code_helper) {
130-
DbState state(State::WaitCode, api_id, api_hash);
131+
DbState state(State::WaitCode, api_id, std::move(api_hash));
131132
state.send_code_helper_ = std::move(send_code_helper);
132133
return state;
133134
}
134135

135136
static DbState wait_qr_code_confirmation(int32 api_id, string api_hash, vector<UserId> other_user_ids,
136137
string login_token, double login_token_expires_at) {
137-
DbState state(State::WaitQrCodeConfirmation, api_id, api_hash);
138+
DbState state(State::WaitQrCodeConfirmation, api_id, std::move(api_hash));
138139
state.other_user_ids_ = std::move(other_user_ids);
139140
state.login_token_ = std::move(login_token);
140141
state.login_token_expires_at_ = login_token_expires_at;
141142
return state;
142143
}
143144

144145
static DbState wait_password(int32 api_id, string api_hash, WaitPasswordState wait_password_state) {
145-
DbState state(State::WaitPassword, api_id, api_hash);
146+
DbState state(State::WaitPassword, api_id, std::move(api_hash));
146147
state.wait_password_state_ = std::move(wait_password_state);
147148
return state;
148149
}
149150

150151
static DbState wait_registration(int32 api_id, string api_hash, SendCodeHelper send_code_helper,
151152
TermsOfService terms_of_service) {
152-
DbState state(State::WaitRegistration, api_id, api_hash);
153+
DbState state(State::WaitRegistration, api_id, std::move(api_hash));
153154
state.send_code_helper_ = std::move(send_code_helper);
154155
state.terms_of_service_ = std::move(terms_of_service);
155156
return state;
@@ -161,8 +162,8 @@ class AuthManager final : public NetActor {
161162
void parse(ParserT &parser);
162163

163164
private:
164-
DbState(State state, int32 api_id, string api_hash)
165-
: state_(state), api_id_(api_id), api_hash_(api_hash), state_timestamp_(Timestamp::now()) {
165+
DbState(State state, int32 api_id, string &&api_hash)
166+
: state_(state), api_id_(api_id), api_hash_(std::move(api_hash)), state_timestamp_(Timestamp::now()) {
166167
}
167168
};
168169

@@ -216,7 +217,6 @@ class AuthManager final : public NetActor {
216217

217218
void on_new_query(uint64 query_id);
218219
void on_query_error(Status status);
219-
void on_query_error(uint64 id, Status status);
220220
void on_query_ok();
221221
void start_net_query(NetQueryType net_query_type, NetQueryPtr net_query);
222222

@@ -232,7 +232,7 @@ class AuthManager final : public NetActor {
232232
void on_get_password_result(NetQueryPtr &result);
233233
void on_request_password_recovery_result(NetQueryPtr &result);
234234
void on_check_password_recovery_code_result(NetQueryPtr &result);
235-
void on_authentication_result(NetQueryPtr &result, bool expected_flag);
235+
void on_authentication_result(NetQueryPtr &result, bool is_from_current_query);
236236
void on_log_out_result(NetQueryPtr &result);
237237
void on_delete_account_result(NetQueryPtr &result);
238238
void on_get_login_token(tl_object_ptr<telegram_api::auth_LoginToken> login_token);
@@ -242,7 +242,9 @@ class AuthManager final : public NetActor {
242242

243243
void update_state(State new_state, bool force = false, bool should_save_state = true);
244244
tl_object_ptr<td_api::AuthorizationState> get_authorization_state_object(State authorization_state) const;
245-
void send_ok(uint64 query_id);
245+
246+
static void send_ok(uint64 query_id);
247+
static void on_query_error(uint64 query_id, Status status);
246248

247249
void start_up() final;
248250
void tear_down() final;

‎td/telegram/BackgroundManager.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ void BackgroundManager::get_backgrounds(bool for_dark_theme,
453453
}
454454

455455
Result<string> BackgroundManager::get_background_url(const string &name,
456-
td_api::object_ptr<td_api::BackgroundType> background_type) const {
456+
td_api::object_ptr<td_api::BackgroundType> background_type) {
457457
TRY_RESULT(type, BackgroundType::get_background_type(background_type.get()));
458458
auto url = PSTRING() << G()->shared_config().get_option_string("t_me_url", "https://t.me/") << "bg/";
459459
auto link = type.get_link();
@@ -526,7 +526,7 @@ std::pair<BackgroundId, BackgroundType> BackgroundManager::search_background(con
526526
if (queries.size() == 1) {
527527
LOG(INFO) << "Trying to load background " << slug << " from database";
528528
G()->td_db()->get_sqlite_pmc()->get(
529-
get_background_name_database_key(slug), PromiseCreator::lambda([slug](string value) {
529+
get_background_name_database_key(slug), PromiseCreator::lambda([slug](string value) mutable {
530530
send_closure(G()->background_manager(), &BackgroundManager::on_load_background_from_database,
531531
std::move(slug), std::move(value));
532532
}));
@@ -563,7 +563,7 @@ void BackgroundManager::on_load_background_from_database(string name, string val
563563
} else {
564564
if (background.name != name) {
565565
LOG(ERROR) << "Expected background " << name << ", but received " << background.name;
566-
name_to_background_id_.emplace(name, background.id);
566+
name_to_background_id_.emplace(std::move(name), background.id);
567567
}
568568
add_background(background, false);
569569
}

‎td/telegram/BackgroundManager.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class BackgroundManager final : public Actor {
3636

3737
void get_backgrounds(bool for_dark_theme, Promise<td_api::object_ptr<td_api::backgrounds>> &&promise);
3838

39-
Result<string> get_background_url(const string &name,
40-
td_api::object_ptr<td_api::BackgroundType> background_type) const;
39+
static Result<string> get_background_url(const string &name,
40+
td_api::object_ptr<td_api::BackgroundType> background_type);
4141

4242
void reload_background(BackgroundId background_id, int64 access_hash, Promise<Unit> &&promise);
4343

‎td/telegram/BackgroundType.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ bool BackgroundFill::is_dark() const {
222222
(fourth_color_ == -1 || (fourth_color_ & 0x808080) == 0);
223223
default:
224224
UNREACHABLE();
225-
return 0;
225+
return false;
226226
}
227227
}
228228

‎td/telegram/CallActor.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ Status CallActor::do_update_call(telegram_api::phoneCall &call) {
484484
get_emojis_fingerprint(call_state_.key, is_outgoing_ ? dh_handshake_.get_g_b() : dh_handshake_.get_g_a());
485485

486486
for (auto &connection : call.connections_) {
487-
call_state_.connections.push_back(CallConnection(*connection));
487+
call_state_.connections.emplace_back(*connection);
488488
}
489489
call_state_.protocol = CallProtocol(*call.protocol_);
490490
call_state_.allow_p2p = (call.flags_ & telegram_api::phoneCall::P2P_ALLOWED_MASK) != 0;

‎td/telegram/CallActor.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct CallState {
7070
enum class Type : int32 { Empty, Pending, ExchangingKey, Ready, HangingUp, Discarded, Error } type{Type::Empty};
7171

7272
CallProtocol protocol;
73-
std::vector<CallConnection> connections;
73+
vector<CallConnection> connections;
7474
CallDiscardReason discard_reason{CallDiscardReason::Empty};
7575
bool is_created{false};
7676
bool is_received{false};

‎td/telegram/CallbackQueriesManager.cpp‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ class GetBotCallbackAnswerQuery final : public Td::ResultHandler {
7979
return on_error(id, result_ptr.move_as_error());
8080
}
8181

82-
td->callback_queries_manager_->on_get_callback_query_answer(result_ptr.move_as_ok(), std::move(promise_));
82+
auto answer = result_ptr.move_as_ok();
83+
bool show_alert = (answer->flags_ & telegram_api::messages_botCallbackAnswer::ALERT_MASK) != 0;
84+
promise_.set_value(td_api::make_object<td_api::callbackQueryAnswer>(answer->message_, show_alert, answer->url_));
8385
}
8486

8587
void on_error(uint64 id, Status status) final {
@@ -288,12 +290,4 @@ void CallbackQueriesManager::send_get_callback_answer_query(
288290
->send(dialog_id, full_message_id.get_message_id(), payload, std::move(password));
289291
}
290292

291-
void CallbackQueriesManager::on_get_callback_query_answer(
292-
tl_object_ptr<telegram_api::messages_botCallbackAnswer> &&answer,
293-
Promise<td_api::object_ptr<td_api::callbackQueryAnswer>> &&promise) {
294-
CHECK(answer != nullptr);
295-
bool show_alert = (answer->flags_ & BOT_CALLBACK_ANSWER_FLAG_NEED_SHOW_ALERT) != 0;
296-
promise.set_value(td_api::make_object<td_api::callbackQueryAnswer>(answer->message_, show_alert, answer->url_));
297-
}
298-
299293
} // namespace td

‎td/telegram/CallbackQueriesManager.h‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,13 @@ class CallbackQueriesManager {
4242
void send_callback_query(FullMessageId full_message_id, tl_object_ptr<td_api::CallbackQueryPayload> &&payload,
4343
Promise<td_api::object_ptr<td_api::callbackQueryAnswer>> &&promise);
4444

45-
void on_get_callback_query_answer(tl_object_ptr<telegram_api::messages_botCallbackAnswer> &&answer,
46-
Promise<td_api::object_ptr<td_api::callbackQueryAnswer>> &&promise);
47-
4845
private:
4946
static constexpr int32 BOT_CALLBACK_ANSWER_FLAG_HAS_MESSAGE = 1 << 0;
5047
static constexpr int32 BOT_CALLBACK_ANSWER_FLAG_NEED_SHOW_ALERT = 1 << 1;
5148
static constexpr int32 BOT_CALLBACK_ANSWER_FLAG_HAS_URL = 1 << 2;
5249

53-
tl_object_ptr<td_api::CallbackQueryPayload> get_query_payload(int32 flags, BufferSlice &&data,
54-
string &&game_short_name);
50+
static tl_object_ptr<td_api::CallbackQueryPayload> get_query_payload(int32 flags, BufferSlice &&data,
51+
string &&game_short_name);
5552

5653
void send_get_callback_answer_query(FullMessageId full_message_id,
5754
tl_object_ptr<td_api::CallbackQueryPayload> &&payload,

0 commit comments

Comments
 (0)