diff --git a/td/telegram/ConfigShared.h b/td/telegram/ConfigShared.h index c49d8b4c0..a9b8e89b1 100644 --- a/td/telegram/ConfigShared.h +++ b/td/telegram/ConfigShared.h @@ -25,7 +25,7 @@ class ConfigShared { Callback(const Callback &) = delete; Callback &operator=(const Callback &) = delete; virtual ~Callback() = default; - virtual void on_option_updated(const string &name, const string &value) = 0; + virtual void on_option_updated(const string &name, const string &value) const = 0; }; ConfigShared(BinlogPmcPtr config_pmc, unique_ptr callback); diff --git a/td/telegram/Game.cpp b/td/telegram/Game.cpp index ce17046c5..f065ca073 100644 --- a/td/telegram/Game.cpp +++ b/td/telegram/Game.cpp @@ -91,7 +91,7 @@ const FormattedText &Game::get_message_text() const { return text_; } -tl_object_ptr Game::get_game_object(const Td *td) const { +tl_object_ptr Game::get_game_object(Td *td) const { return make_tl_object( id_, short_name_, title_, get_formatted_text_object(text_), description_, get_photo_object(td->file_manager_.get(), &photo_), diff --git a/td/telegram/Game.h b/td/telegram/Game.h index a9b2a3204..98eed6642 100644 --- a/td/telegram/Game.h +++ b/td/telegram/Game.h @@ -59,7 +59,7 @@ class Game { const FormattedText &get_message_text() const; - tl_object_ptr get_game_object(const Td *td) const; + tl_object_ptr get_game_object(Td *td) const; tl_object_ptr get_input_media_game(const Td *td) const; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index fac5d7a98..c53ad484d 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -12755,7 +12755,7 @@ Status MessagesManager::delete_dialog_reply_markup(DialogId dialog_id, MessageId return Status::OK(); } - const Message *message = get_message_force(d, message_id); + Message *message = get_message_force(d, message_id); CHECK(message != nullptr); CHECK(message->reply_markup != nullptr); @@ -14140,7 +14140,7 @@ tl_object_ptr MessagesManager::get_dialog_history(DialogId dia if (*p == nullptr) { // there is no gap if from_message_id is less than first message in the dialog if (left_tries == 0 && d->messages != nullptr && offset < 0) { - Message *cur = d->messages.get(); + const Message *cur = d->messages.get(); while (cur->left != nullptr) { cur = cur->left.get(); } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index faa747e45..df2132eb0 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1585,7 +1585,7 @@ class MessagesManager : public Actor { unique_ptr left; unique_ptr right; - int32 last_access_date = 0; + mutable int32 last_access_date = 0; uint64 send_message_logevent_id = 0; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 7c8e36b5d..0c6fa6103 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -4053,7 +4053,7 @@ Status Td::init(DbKey key) { VLOG(td_init) << "Create ConfigManager and ConfigShared"; class ConfigSharedCallback : public ConfigShared::Callback { public: - void on_option_updated(const string &name, const string &value) override { + void on_option_updated(const string &name, const string &value) const override { send_closure(G()->td(), &Td::on_config_option_updated, name); } }; diff --git a/td/telegram/files/FileGenerateManager.cpp b/td/telegram/files/FileGenerateManager.cpp index 6240c435f..d04930f60 100644 --- a/td/telegram/files/FileGenerateManager.cpp +++ b/td/telegram/files/FileGenerateManager.cpp @@ -88,17 +88,18 @@ class FileDownloadGenerateActor : public FileGenerateActor { } void on_download_ok() { - send_lambda(G()->file_manager(), [file_type = file_type_, file_id = file_id_, callback = std::move(callback_)] { - auto file_view = G()->td().get_actor_unsafe()->file_manager_->get_file_view(file_id); - if (file_view.has_local_location()) { - auto location = file_view.local_location(); - location.file_type_ = file_type; - callback->on_ok(location); - } else { - LOG(ERROR) << "Expected to have local location"; - callback->on_error(Status::Error(500, "Unknown")); - } - }); + send_lambda(G()->file_manager(), + [file_type = file_type_, file_id = file_id_, callback = std::move(callback_)]() mutable { + auto file_view = G()->td().get_actor_unsafe()->file_manager_->get_file_view(file_id); + if (file_view.has_local_location()) { + auto location = file_view.local_location(); + location.file_type_ = file_type; + callback->on_ok(location); + } else { + LOG(ERROR) << "Expected to have local location"; + callback->on_error(Status::Error(500, "Unknown")); + } + }); stop(); } void on_download_error(Status error) { diff --git a/td/tl/TlObject.h b/td/tl/TlObject.h index eaeecae0e..c93066fba 100644 --- a/td/tl/TlObject.h +++ b/td/tl/TlObject.h @@ -175,6 +175,7 @@ template bool operator!=(const unique_ptr &p, std::nullptr_t) { return static_cast(p); } + } // namespace tl template using tl_object_ptr = tl::unique_ptr; diff --git a/tdutils/td/utils/unique_ptr.h b/tdutils/td/utils/unique_ptr.h index ee6e25e30..959dedf55 100644 --- a/tdutils/td/utils/unique_ptr.h +++ b/tdutils/td/utils/unique_ptr.h @@ -12,8 +12,10 @@ namespace td { +// const-correct and compiler-friendly (g++ RAM and CPU usage 10 times less than for std::unique_ptr) +// replacement for std::unique_ptr template -class unique_ptr { +class unique_ptr final { public: using pointer = T *; using element_type = T; @@ -52,13 +54,22 @@ class unique_ptr { ptr_ = nullptr; return res; } - T *get() const noexcept { + T *get() noexcept { return ptr_; } - T *operator->() const noexcept { + const T *get() const noexcept { return ptr_; } - T &operator*() const noexcept { + T *operator->() noexcept { + return ptr_; + } + const T *operator->() const noexcept { + return ptr_; + } + T &operator*() noexcept { + return *ptr_; + } + const T &operator*() const noexcept { return *ptr_; } explicit operator bool() const noexcept {