Const-correct unique_ptr.
GitOrigin-RevId: 938cf4b0261cfea123066ae1fc4197754da11e68
This commit is contained in:
parent
c3417b5f94
commit
6ac930139b
|
@ -25,7 +25,7 @@ class ConfigShared {
|
||||||
Callback(const Callback &) = delete;
|
Callback(const Callback &) = delete;
|
||||||
Callback &operator=(const Callback &) = delete;
|
Callback &operator=(const Callback &) = delete;
|
||||||
virtual ~Callback() = default;
|
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> callback);
|
ConfigShared(BinlogPmcPtr config_pmc, unique_ptr<Callback> callback);
|
||||||
|
|
|
@ -91,7 +91,7 @@ const FormattedText &Game::get_message_text() const {
|
||||||
return text_;
|
return text_;
|
||||||
}
|
}
|
||||||
|
|
||||||
tl_object_ptr<td_api::game> Game::get_game_object(const Td *td) const {
|
tl_object_ptr<td_api::game> Game::get_game_object(Td *td) const {
|
||||||
return make_tl_object<td_api::game>(
|
return make_tl_object<td_api::game>(
|
||||||
id_, short_name_, title_, get_formatted_text_object(text_), description_,
|
id_, short_name_, title_, get_formatted_text_object(text_), description_,
|
||||||
get_photo_object(td->file_manager_.get(), &photo_),
|
get_photo_object(td->file_manager_.get(), &photo_),
|
||||||
|
|
|
@ -59,7 +59,7 @@ class Game {
|
||||||
|
|
||||||
const FormattedText &get_message_text() const;
|
const FormattedText &get_message_text() const;
|
||||||
|
|
||||||
tl_object_ptr<td_api::game> get_game_object(const Td *td) const;
|
tl_object_ptr<td_api::game> get_game_object(Td *td) const;
|
||||||
|
|
||||||
tl_object_ptr<telegram_api::inputMediaGame> get_input_media_game(const Td *td) const;
|
tl_object_ptr<telegram_api::inputMediaGame> get_input_media_game(const Td *td) const;
|
||||||
|
|
||||||
|
|
|
@ -12755,7 +12755,7 @@ Status MessagesManager::delete_dialog_reply_markup(DialogId dialog_id, MessageId
|
||||||
return Status::OK();
|
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 != nullptr);
|
||||||
CHECK(message->reply_markup != nullptr);
|
CHECK(message->reply_markup != nullptr);
|
||||||
|
|
||||||
|
@ -14140,7 +14140,7 @@ tl_object_ptr<td_api::messages> MessagesManager::get_dialog_history(DialogId dia
|
||||||
if (*p == nullptr) {
|
if (*p == nullptr) {
|
||||||
// there is no gap if from_message_id is less than first message in the dialog
|
// 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) {
|
if (left_tries == 0 && d->messages != nullptr && offset < 0) {
|
||||||
Message *cur = d->messages.get();
|
const Message *cur = d->messages.get();
|
||||||
while (cur->left != nullptr) {
|
while (cur->left != nullptr) {
|
||||||
cur = cur->left.get();
|
cur = cur->left.get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1585,7 +1585,7 @@ class MessagesManager : public Actor {
|
||||||
unique_ptr<Message> left;
|
unique_ptr<Message> left;
|
||||||
unique_ptr<Message> right;
|
unique_ptr<Message> right;
|
||||||
|
|
||||||
int32 last_access_date = 0;
|
mutable int32 last_access_date = 0;
|
||||||
|
|
||||||
uint64 send_message_logevent_id = 0;
|
uint64 send_message_logevent_id = 0;
|
||||||
|
|
||||||
|
|
|
@ -4053,7 +4053,7 @@ Status Td::init(DbKey key) {
|
||||||
VLOG(td_init) << "Create ConfigManager and ConfigShared";
|
VLOG(td_init) << "Create ConfigManager and ConfigShared";
|
||||||
class ConfigSharedCallback : public ConfigShared::Callback {
|
class ConfigSharedCallback : public ConfigShared::Callback {
|
||||||
public:
|
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);
|
send_closure(G()->td(), &Td::on_config_option_updated, name);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -88,17 +88,18 @@ class FileDownloadGenerateActor : public FileGenerateActor {
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_download_ok() {
|
void on_download_ok() {
|
||||||
send_lambda(G()->file_manager(), [file_type = file_type_, file_id = file_id_, callback = std::move(callback_)] {
|
send_lambda(G()->file_manager(),
|
||||||
auto file_view = G()->td().get_actor_unsafe()->file_manager_->get_file_view(file_id);
|
[file_type = file_type_, file_id = file_id_, callback = std::move(callback_)]() mutable {
|
||||||
if (file_view.has_local_location()) {
|
auto file_view = G()->td().get_actor_unsafe()->file_manager_->get_file_view(file_id);
|
||||||
auto location = file_view.local_location();
|
if (file_view.has_local_location()) {
|
||||||
location.file_type_ = file_type;
|
auto location = file_view.local_location();
|
||||||
callback->on_ok(location);
|
location.file_type_ = file_type;
|
||||||
} else {
|
callback->on_ok(location);
|
||||||
LOG(ERROR) << "Expected to have local location";
|
} else {
|
||||||
callback->on_error(Status::Error(500, "Unknown"));
|
LOG(ERROR) << "Expected to have local location";
|
||||||
}
|
callback->on_error(Status::Error(500, "Unknown"));
|
||||||
});
|
}
|
||||||
|
});
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
void on_download_error(Status error) {
|
void on_download_error(Status error) {
|
||||||
|
|
|
@ -175,6 +175,7 @@ template <class T>
|
||||||
bool operator!=(const unique_ptr<T> &p, std::nullptr_t) {
|
bool operator!=(const unique_ptr<T> &p, std::nullptr_t) {
|
||||||
return static_cast<bool>(p);
|
return static_cast<bool>(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace tl
|
} // namespace tl
|
||||||
template <class Type>
|
template <class Type>
|
||||||
using tl_object_ptr = tl::unique_ptr<Type>;
|
using tl_object_ptr = tl::unique_ptr<Type>;
|
||||||
|
|
|
@ -12,8 +12,10 @@
|
||||||
|
|
||||||
namespace td {
|
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 T>
|
template <class T>
|
||||||
class unique_ptr {
|
class unique_ptr final {
|
||||||
public:
|
public:
|
||||||
using pointer = T *;
|
using pointer = T *;
|
||||||
using element_type = T;
|
using element_type = T;
|
||||||
|
@ -52,13 +54,22 @@ class unique_ptr {
|
||||||
ptr_ = nullptr;
|
ptr_ = nullptr;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
T *get() const noexcept {
|
T *get() noexcept {
|
||||||
return ptr_;
|
return ptr_;
|
||||||
}
|
}
|
||||||
T *operator->() const noexcept {
|
const T *get() const noexcept {
|
||||||
return ptr_;
|
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_;
|
return *ptr_;
|
||||||
}
|
}
|
||||||
explicit operator bool() const noexcept {
|
explicit operator bool() const noexcept {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user