diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 9adbeea2..5276b92a 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -2679,7 +2679,7 @@ void ContactsManager::UserFull::store(StorerT &storer) const { STORE_FLAG(has_private_calls); END_STORE_FLAGS(); if (has_bot_info) { - store(*bot_info, storer); + store(bot_info, storer); } if (has_about) { store(about, storer); @@ -2702,8 +2702,7 @@ void ContactsManager::UserFull::parse(ParserT &parser) { PARSE_FLAG(has_private_calls); END_PARSE_FLAGS(); if (has_bot_info) { - bot_info = make_unique(); - parse(*bot_info, parser); + parse(bot_info, parser); } if (has_about) { parse(about, parser); diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 14352cb3..5264a99c 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -942,7 +942,7 @@ static void store(const MessageContent *content, StorerT &storer) { store(m->invoice_payload, storer); } if (has_order_info) { - store(*m->order_info, storer); + store(m->order_info, storer); } if (has_telegram_payment_charge_id) { store(m->telegram_payment_charge_id, storer); @@ -1274,8 +1274,7 @@ static void parse(unique_ptr &content, ParserT &parser) { parse(m->invoice_payload, parser); } if (has_order_info) { - m->order_info = make_unique(); - parse(*m->order_info, parser); + parse(m->order_info, parser); } if (has_telegram_payment_charge_id) { parse(m->telegram_payment_charge_id, parser); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 3f889063..72cefc64 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -3858,7 +3858,7 @@ void MessagesManager::Message::store(StorerT &storer) const { } store_message_content(content.get(), storer); if (has_reply_markup) { - store(*reply_markup, storer); + store(reply_markup, storer); } } @@ -4009,8 +4009,7 @@ void MessagesManager::Message::parse(ParserT &parser) { } parse_message_content(content, parser); if (has_reply_markup) { - reply_markup = make_unique(); - parse(*reply_markup, parser); + parse(reply_markup, parser); } is_content_secret |= is_secret_message_content(ttl, content->get_type()); // repair is_content_secret for old messages @@ -4125,7 +4124,7 @@ void MessagesManager::Dialog::store(StorerT &storer) const { store(reply_markup_message_id, storer); store(notification_settings, storer); if (has_draft_message) { - store(*draft_message, storer); + store(draft_message, storer); } store(last_clear_history_date, storer); store(order, storer); @@ -4284,14 +4283,12 @@ void MessagesManager::Dialog::parse(ParserT &parser) { parse(reply_markup_message_id, parser); parse(notification_settings, parser); if (has_draft_message) { - draft_message = make_unique(); - parse(*draft_message, parser); + parse(draft_message, parser); } parse(last_clear_history_date, parser); parse(order, parser); if (has_last_database_message) { - messages = make_unique(); - parse(*messages, parser); + parse(messages, parser); } if (has_first_database_message_id) { parse(first_database_message_id, parser); @@ -16779,9 +16776,7 @@ class MessagesManager::SendMessageLogEvent { template void parse(ParserT &parser) { td::parse(dialog_id, parser); - CHECK(m_out == nullptr); - m_out = make_unique(); - td::parse(*m_out, parser); + td::parse(m_out, parser); } }; @@ -17586,9 +17581,7 @@ class MessagesManager::SendBotStartMessageLogEvent { td::parse(bot_user_id, parser); td::parse(dialog_id, parser); td::parse(parameter, parser); - CHECK(m_out == nullptr); - m_out = make_unique(); - td::parse(*m_out, parser); + td::parse(m_out, parser); } }; @@ -17725,9 +17718,7 @@ class MessagesManager::SendInlineQueryResultMessageLogEvent { td::parse(dialog_id, parser); td::parse(query_id, parser); td::parse(result_id, parser); - CHECK(m_out == nullptr); - m_out = make_unique(); - td::parse(*m_out, parser); + td::parse(m_out, parser); } }; @@ -18943,8 +18934,7 @@ class MessagesManager::ForwardMessagesLogEvent { int32 size = parser.fetch_int(); messages_out.resize(size); for (auto &m_out : messages_out) { - m_out = make_unique(); - td::parse(*m_out, parser); + td::parse(m_out, parser); } } }; @@ -19445,9 +19435,7 @@ class MessagesManager::SendScreenshotTakenNotificationMessageLogEvent { template void parse(ParserT &parser) { td::parse(dialog_id, parser); - CHECK(m_out == nullptr); - m_out = make_unique(); - td::parse(*m_out, parser); + td::parse(m_out, parser); } }; diff --git a/td/telegram/Payments.hpp b/td/telegram/Payments.hpp index 4bc1f76b..1ae66ea5 100644 --- a/td/telegram/Payments.hpp +++ b/td/telegram/Payments.hpp @@ -100,7 +100,7 @@ void store(const OrderInfo &order_info, StorerT &storer) { store(order_info.email_address, storer); } if (has_shipping_address) { - store(*order_info.shipping_address, storer); + store(order_info.shipping_address, storer); } } @@ -126,8 +126,7 @@ void parse(OrderInfo &order_info, ParserT &parser) { parse(order_info.email_address, parser); } if (has_shipping_address) { - order_info.shipping_address = make_unique
(); - parse(*order_info.shipping_address, parser); + parse(order_info.shipping_address, parser); } } diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index 0e2c6125..dd6b30b9 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -1299,9 +1299,7 @@ class WebPagesManager::WebPageLogEvent { template void parse(ParserT &parser) { td::parse(web_page_id, parser); - CHECK(web_page_out == nullptr); - web_page_out = make_unique(); - td::parse(*web_page_out, parser); + td::parse(web_page_out, parser); } }; diff --git a/tdutils/td/utils/tl_helpers.h b/tdutils/td/utils/tl_helpers.h index 725ab9d4..32da5830 100644 --- a/tdutils/td/utils/tl_helpers.h +++ b/tdutils/td/utils/tl_helpers.h @@ -151,6 +151,18 @@ void parse(vector &vec, ParserT &parser) { } } +template +void store(const unique_ptr &ptr, StorerT &storer) { + CHECK(ptr != nullptr); + store(*ptr, storer); +} +template +void parse(unique_ptr &ptr, ParserT &parser) { + CHECK(ptr == nullptr); + ptr = make_unique(); + parse(*ptr, parser); +} + template void store(const std::unordered_set &s, StorerT &storer) { storer.store_binary(narrow_cast(s.size()));