Move other big classes inside FlatHashMap to unique_ptr.

This commit is contained in:
levlam 2022-02-11 19:27:32 +03:00
parent e64811ba31
commit 15f27455c5
14 changed files with 110 additions and 69 deletions

View File

@ -976,7 +976,11 @@ void BackgroundManager::add_background(const Background &background, bool replac
LOG(INFO) << "Add " << background.id << " of " << background.type;
CHECK(background.id.is_valid());
auto *result = &backgrounds_[background.id];
auto &result_ptr = backgrounds_[background.id];
if (result_ptr == nullptr) {
result_ptr = make_unique<Background>();
}
auto *result = result_ptr.get();
FileSourceId file_source_id;
auto it = background_id_to_file_source_id_.find(background.id);
@ -1055,7 +1059,7 @@ BackgroundManager::Background *BackgroundManager::get_background_ref(BackgroundI
if (p == backgrounds_.end()) {
return nullptr;
} else {
return &p->second;
return p->second.get();
}
}
@ -1064,7 +1068,7 @@ const BackgroundManager::Background *BackgroundManager::get_background(Backgroun
if (p == backgrounds_.end()) {
return nullptr;
} else {
return &p->second;
return p->second.get();
}
}

View File

@ -160,7 +160,7 @@ class BackgroundManager final : public Actor {
void do_upload_background_file(FileId file_id, const BackgroundType &type, bool for_dark_theme,
tl_object_ptr<telegram_api::InputFile> &&input_file, Promise<Unit> &&promise);
FlatHashMap<BackgroundId, Background, BackgroundIdHash> backgrounds_;
FlatHashMap<BackgroundId, unique_ptr<Background>, BackgroundIdHash> backgrounds_;
FlatHashMap<BackgroundId, std::pair<int64, FileSourceId>, BackgroundIdHash>
background_id_to_file_source_id_; // id -> [access_hash, file_source_id]

View File

@ -40,6 +40,16 @@ struct LanguagePackManager::PluralizedString {
string few_value_;
string many_value_;
string other_value_;
PluralizedString(string &&zero_value, string &&one_value, string &&two_value, string &&few_value, string &&many_value,
string &&other_value)
: zero_value_(std::move(zero_value))
, one_value_(std::move(one_value))
, two_value_(std::move(two_value))
, few_value_(std::move(few_value))
, many_value_(std::move(many_value))
, other_value_(std::move(other_value)) {
}
};
struct LanguagePackManager::Language {
@ -52,7 +62,7 @@ struct LanguagePackManager::Language {
bool has_get_difference_query_ = false;
vector<Promise<Unit>> get_difference_queries_;
FlatHashMap<string, string> ordinary_strings_;
FlatHashMap<string, PluralizedString> pluralized_strings_;
FlatHashMap<string, unique_ptr<PluralizedString>> pluralized_strings_;
std::unordered_set<string> deleted_strings_;
SqliteKeyValue kv_; // usages should be guarded by database_->mutex_
};
@ -84,7 +94,7 @@ struct LanguagePackManager::LanguagePack {
SqliteKeyValue pack_kv_; // usages should be guarded by database_->mutex_
std::map<string, LanguageInfo> custom_language_pack_infos_; // sorted by language_code
vector<std::pair<string, LanguageInfo>> server_language_pack_infos_; // sorted by server
FlatHashMap<string, LanguageInfo> all_server_language_pack_infos_;
FlatHashMap<string, unique_ptr<LanguageInfo>> all_server_language_pack_infos_;
FlatHashMap<string, unique_ptr<Language>> languages_;
};
@ -588,7 +598,7 @@ LanguagePackManager::Language *LanguagePackManager::add_language(LanguageDatabas
info.total_string_count_ = to_integer<int32>(all_infos[i + 8]);
info.translated_string_count_ = to_integer<int32>(all_infos[i + 9]);
info.translation_url_ = std::move(all_infos[i + 10]);
pack->all_server_language_pack_infos_.emplace(all_infos[i], info);
pack->all_server_language_pack_infos_.emplace(all_infos[i], td::make_unique<LanguageInfo>(info));
pack->server_language_pack_infos_.emplace_back(std::move(all_infos[i]), std::move(info));
}
} else {
@ -683,7 +693,8 @@ void LanguagePackManager::load_language_string_unsafe(Language *language, const
auto all = full_split(Slice(value).substr(1), '\x00');
if (all.size() == 6) {
language->pluralized_strings_.emplace(
key, PluralizedString{all[0].str(), all[1].str(), all[2].str(), all[3].str(), all[4].str(), all[5].str()});
key, td::make_unique<PluralizedString>(all[0].str(), all[1].str(), all[2].str(), all[3].str(), all[4].str(),
all[5].str()));
return;
}
}
@ -797,7 +808,7 @@ td_api::object_ptr<td_api::LanguagePackStringValue> LanguagePackManager::get_lan
}
auto pluralized_it = language->pluralized_strings_.find(key);
if (pluralized_it != language->pluralized_strings_.end()) {
return get_language_pack_string_value_object(pluralized_it->second);
return get_language_pack_string_value_object(*pluralized_it->second);
}
LOG_IF(ERROR, !language->is_full_ && language->deleted_strings_.count(key) == 0) << "Have no string for key " << key;
return get_language_pack_string_value_object();
@ -819,7 +830,7 @@ td_api::object_ptr<td_api::languagePackStrings> LanguagePackManager::get_languag
strings.push_back(get_language_pack_string_object(str.first, str.second));
}
for (auto &str : language->pluralized_strings_) {
strings.push_back(get_language_pack_string_object(str.first, str.second));
strings.push_back(get_language_pack_string_object(str.first, *str.second));
}
} else {
for (auto &key : keys) {
@ -1018,7 +1029,7 @@ void LanguagePackManager::on_get_languages(vector<tl_object_ptr<telegram_api::la
std::lock_guard<std::mutex> pack_lock(pack->mutex_);
if (pack->server_language_pack_infos_ != all_server_infos) {
for (auto &info : all_server_infos) {
pack->all_server_language_pack_infos_[info.first] = info.second;
pack->all_server_language_pack_infos_[info.first] = td::make_unique<LanguageInfo>(info.second);
}
pack->server_language_pack_infos_ = std::move(all_server_infos);
@ -1062,7 +1073,8 @@ void LanguagePackManager::on_get_language(tl_object_ptr<telegram_api::langPackLa
}
}
}
pack->all_server_language_pack_infos_[lang_pack_language->lang_code_] = r_info.move_as_ok();
pack->all_server_language_pack_infos_[lang_pack_language->lang_code_] =
td::make_unique<LanguageInfo>(r_info.move_as_ok());
if (is_changed) {
save_server_language_pack_infos(pack);
@ -1396,9 +1408,9 @@ void LanguagePackManager::on_get_language_pack_strings(
LOG(ERROR) << "Receive invalid key \"" << str->key_ << '"';
break;
}
PluralizedString value{std::move(str->zero_value_), std::move(str->one_value_),
std::move(str->two_value_), std::move(str->few_value_),
std::move(str->many_value_), std::move(str->other_value_)};
auto value = td::make_unique<PluralizedString>(std::move(str->zero_value_), std::move(str->one_value_),
std::move(str->two_value_), std::move(str->few_value_),
std::move(str->many_value_), std::move(str->other_value_));
auto it = language->pluralized_strings_.find(str->key_);
if (it == language->pluralized_strings_.end()) {
key_count_delta++;
@ -1409,13 +1421,13 @@ void LanguagePackManager::on_get_language_pack_strings(
key_count_delta -= static_cast<int32>(language->ordinary_strings_.erase(str->key_));
language->deleted_strings_.erase(str->key_);
if (is_diff) {
strings.push_back(get_language_pack_string_object(it->first, it->second));
strings.push_back(get_language_pack_string_object(it->first, *it->second));
}
database_strings.emplace_back(
std::move(str->key_), PSTRING()
<< '2' << it->second.zero_value_ << '\x00' << it->second.one_value_ << '\x00'
<< it->second.two_value_ << '\x00' << it->second.few_value_ << '\x00'
<< it->second.many_value_ << '\x00' << it->second.other_value_);
<< '2' << it->second->zero_value_ << '\x00' << it->second->one_value_
<< '\x00' << it->second->two_value_ << '\x00' << it->second->few_value_
<< '\x00' << it->second->many_value_ << '\x00' << it->second->other_value_);
break;
}
case telegram_api::langPackStringDeleted::ID: {
@ -1554,7 +1566,7 @@ void LanguagePackManager::add_custom_server_language(string language_code, Promi
return promise.set_error(Status::Error(400, "Language pack info not found"));
}
auto &info = pack->custom_language_pack_infos_[language_code];
info = it->second;
info = *it->second;
if (!pack->pack_kv_.empty()) {
pack->pack_kv_.set(language_code, get_language_info_string(info));
}

View File

@ -957,7 +957,11 @@ void SecureManager::get_passport_authorization_form(UserId bot_user_id, string s
refcnt_++;
CHECK(max_authorization_form_id_ < std::numeric_limits<int32>::max());
auto authorization_form_id = ++max_authorization_form_id_;
auto &form = authorization_forms_[authorization_form_id];
auto &form_ptr = authorization_forms_[authorization_form_id];
if (form_ptr == nullptr) {
form_ptr = make_unique<AuthorizationForm>();
}
auto &form = *form_ptr;
form.bot_user_id = bot_user_id;
form.scope = scope;
form.public_key = public_key;
@ -978,7 +982,8 @@ void SecureManager::on_get_passport_authorization_form(
Result<telegram_api::object_ptr<telegram_api::account_authorizationForm>> r_authorization_form) {
auto it = authorization_forms_.find(authorization_form_id);
CHECK(it != authorization_forms_.end());
CHECK(it->second.is_received == false);
CHECK(it->second != nullptr);
CHECK(!it->second->is_received);
if (r_authorization_form.is_error()) {
authorization_forms_.erase(it);
return promise.set_error(r_authorization_form.move_as_error());
@ -1022,10 +1027,10 @@ void SecureManager::on_get_passport_authorization_form(
}
}
it->second.options = std::move(all_types);
it->second.values = std::move(authorization_form->values_);
it->second.errors = std::move(authorization_form->errors_);
it->second.is_received = true;
it->second->options = std::move(all_types);
it->second->values = std::move(authorization_form->values_);
it->second->errors = std::move(authorization_form->errors_);
it->second->is_received = true;
promise.set_value(td_api::make_object<td_api::passportAuthorizationForm>(
authorization_form_id, get_passport_required_elements_object(required_types),
@ -1038,7 +1043,8 @@ void SecureManager::get_passport_authorization_form_available_elements(int32 aut
if (it == authorization_forms_.end()) {
return promise.set_error(Status::Error(400, "Unknown authorization_form_id"));
}
if (!it->second.is_received) {
CHECK(it->second != nullptr);
if (!it->second->is_received) {
return promise.set_error(Status::Error(400, "Authorization form isn't received yet"));
}
@ -1058,8 +1064,9 @@ void SecureManager::on_get_passport_authorization_form_secret(int32 authorizatio
if (it == authorization_forms_.end()) {
return promise.set_error(Status::Error(400, "Authorization form has already been sent"));
}
CHECK(it->second.is_received);
if (it->second.is_decrypted) {
CHECK(it->second != nullptr);
CHECK(it->second->is_received);
if (it->second->is_decrypted) {
return promise.set_error(Status::Error(400, "Authorization form has already been decrypted"));
}
@ -1075,14 +1082,14 @@ void SecureManager::on_get_passport_authorization_form_secret(int32 authorizatio
}
auto secret = r_secret.move_as_ok();
it->second.is_decrypted = true;
it->second->is_decrypted = true;
auto *file_manager = G()->td().get_actor_unsafe()->file_manager_.get();
std::vector<TdApiSecureValue> values;
std::map<SecureValueType, SecureValueCredentials> all_credentials;
for (const auto &suitable_type : it->second.options) {
for (const auto &suitable_type : it->second->options) {
auto type = suitable_type.first;
for (auto &value : it->second.values) {
for (auto &value : it->second->values) {
if (value == nullptr) {
continue;
}
@ -1124,7 +1131,7 @@ void SecureManager::on_get_passport_authorization_form_secret(int32 authorizatio
};
vector<td_api::object_ptr<td_api::passportElementError>> errors;
for (auto &error_ptr : it->second.errors) {
for (auto &error_ptr : it->second->errors) {
CHECK(error_ptr != nullptr);
SecureValueType type = SecureValueType::None;
td_api::object_ptr<td_api::PassportElementErrorSource> source;
@ -1227,7 +1234,8 @@ void SecureManager::send_passport_authorization_form(int32 authorization_form_id
if (it == authorization_forms_.end()) {
return promise.set_error(Status::Error(400, "Unknown authorization_form_id"));
}
if (!it->second.is_received) {
CHECK(it->second != nullptr);
if (!it->second->is_received) {
return promise.set_error(Status::Error(400, "Authorization form isn't received yet"));
}
// there is no need to check for is_decrypted
@ -1249,8 +1257,8 @@ void SecureManager::send_passport_authorization_form(int32 authorization_form_id
for (auto &c : credentials) {
hashes.push_back(telegram_api::make_object<telegram_api::secureValueHash>(get_input_secure_value_type(c.type),
BufferSlice(c.hash)));
auto options_it = it->second.options.find(c.type);
if (options_it == it->second.options.end()) {
auto options_it = it->second->options.find(c.type);
if (options_it == it->second->options.end()) {
return promise.set_error(Status::Error(400, "Passport Element with the specified type was not requested"));
}
auto &options = options_it->second;
@ -1263,14 +1271,14 @@ void SecureManager::send_passport_authorization_form(int32 authorization_form_id
}
auto r_encrypted_credentials =
get_encrypted_credentials(credentials, it->second.nonce, it->second.public_key,
it->second.scope[0] == '{' && it->second.scope.back() == '}');
get_encrypted_credentials(credentials, it->second->nonce, it->second->public_key,
it->second->scope[0] == '{' && it->second->scope.back() == '}');
if (r_encrypted_credentials.is_error()) {
return promise.set_error(r_encrypted_credentials.move_as_error());
}
auto td_query = telegram_api::account_acceptAuthorization(
it->second.bot_user_id.get(), it->second.scope, it->second.public_key, std::move(hashes),
it->second->bot_user_id.get(), it->second->scope, it->second->public_key, std::move(hashes),
get_secure_credentials_encrypted_object(r_encrypted_credentials.move_as_ok()));
auto query = G()->net_query_creator().create(td_query);
auto new_promise =

View File

@ -77,7 +77,7 @@ class SecureManager final : public NetQueryCallback {
vector<telegram_api::object_ptr<telegram_api::SecureValueError>> errors;
};
FlatHashMap<int32, AuthorizationForm> authorization_forms_;
FlatHashMap<int32, unique_ptr<AuthorizationForm>> authorization_forms_;
int32 max_authorization_form_id_{0};
void hangup() final;

View File

@ -1359,7 +1359,11 @@ void StickersManager::reload_reactions() {
StickersManager::SpecialStickerSet &StickersManager::add_special_sticker_set(const SpecialStickerSetType &type) {
CHECK(!type.is_empty());
auto &result = special_sticker_sets_[type];
auto &result_ptr = special_sticker_sets_[type];
if (result_ptr == nullptr) {
result_ptr = make_unique<SpecialStickerSet>();
}
auto &result = *result_ptr;
if (result.type_.is_empty()) {
result.type_ = type;
} else {
@ -1889,7 +1893,7 @@ tl_object_ptr<td_api::DiceStickers> StickersManager::get_dice_stickers_object(co
return nullptr;
}
auto sticker_set_id = it->second.id_;
auto sticker_set_id = it->second->id_;
if (!sticker_set_id.is_valid()) {
return nullptr;
}
@ -2125,7 +2129,7 @@ td_api::object_ptr<td_api::animatedEmoji> StickersManager::get_animated_emoji_ob
if (it == emoji_messages_.end()) {
return get_animated_emoji_object(get_animated_emoji_sticker(emoji), get_animated_emoji_sound_file_id(emoji));
} else {
return get_animated_emoji_object(it->second.animated_emoji_sticker, it->second.sound_file_id);
return get_animated_emoji_object(it->second->animated_emoji_sticker, it->second->sound_file_id);
}
}
@ -4444,11 +4448,11 @@ void StickersManager::try_update_animated_emoji_messages() {
for (auto &it : emoji_messages_) {
auto new_animated_sticker = get_animated_emoji_sticker(sticker_set, it.first);
auto new_sound_file_id = get_animated_emoji_sound_file_id(it.first);
if (new_animated_sticker != it.second.animated_emoji_sticker ||
(new_animated_sticker.first.is_valid() && new_sound_file_id != it.second.sound_file_id)) {
it.second.animated_emoji_sticker = new_animated_sticker;
it.second.sound_file_id = new_sound_file_id;
for (const auto &full_message_id : it.second.full_message_ids) {
if (new_animated_sticker != it.second->animated_emoji_sticker ||
(new_animated_sticker.first.is_valid() && new_sound_file_id != it.second->sound_file_id)) {
it.second->animated_emoji_sticker = new_animated_sticker;
it.second->sound_file_id = new_sound_file_id;
for (const auto &full_message_id : it.second->full_message_ids) {
full_message_ids.push_back(full_message_id);
}
}
@ -4523,7 +4527,11 @@ void StickersManager::register_emoji(const string &emoji, FullMessageId full_mes
}
LOG(INFO) << "Register emoji " << emoji << " from " << full_message_id << " from " << source;
auto &emoji_messages = emoji_messages_[emoji];
auto &emoji_messages_ptr = emoji_messages_[emoji];
if (emoji_messages_ptr == nullptr) {
emoji_messages_ptr = make_unique<EmojiMessages>();
}
auto &emoji_messages = *emoji_messages_ptr;
if (emoji_messages.full_message_ids.empty()) {
emoji_messages.animated_emoji_sticker = get_animated_emoji_sticker(emoji);
emoji_messages.sound_file_id = get_animated_emoji_sound_file_id(emoji);
@ -4541,7 +4549,7 @@ void StickersManager::unregister_emoji(const string &emoji, FullMessageId full_m
LOG(INFO) << "Unregister emoji " << emoji << " from " << full_message_id << " from " << source;
auto it = emoji_messages_.find(emoji);
CHECK(it != emoji_messages_.end());
auto &full_message_ids = it->second.full_message_ids;
auto &full_message_ids = it->second->full_message_ids;
auto is_deleted = full_message_ids.erase(full_message_id) > 0;
LOG_CHECK(is_deleted) << source << ' ' << emoji << ' ' << full_message_id;

View File

@ -837,7 +837,7 @@ class StickersManager final : public Actor {
int32 recent_stickers_limit_ = 200;
int32 favorite_stickers_limit_ = 5;
FlatHashMap<SpecialStickerSetType, SpecialStickerSet, SpecialStickerSetTypeHash> special_sticker_sets_;
FlatHashMap<SpecialStickerSetType, unique_ptr<SpecialStickerSet>, SpecialStickerSetTypeHash> special_sticker_sets_;
struct StickerSetLoadRequest {
Promise<Unit> promise;
@ -893,7 +893,7 @@ class StickersManager final : public Actor {
std::pair<FileId, int> animated_emoji_sticker;
FileId sound_file_id;
};
FlatHashMap<string, EmojiMessages> emoji_messages_;
FlatHashMap<string, unique_ptr<EmojiMessages>> emoji_messages_;
string dice_emojis_str_;
vector<string> dice_emojis_;

View File

@ -1901,7 +1901,7 @@ unique_ptr<WebPageBlock> get_web_page_block(Td *td, tl_object_ptr<telegram_api::
const FlatHashMap<int64, FileId> &animations,
const FlatHashMap<int64, FileId> &audios,
const FlatHashMap<int64, FileId> &documents,
const FlatHashMap<int64, Photo> &photos,
const FlatHashMap<int64, unique_ptr<Photo>> &photos,
const FlatHashMap<int64, FileId> &videos,
const FlatHashMap<int64, FileId> &voice_notes) {
CHECK(page_block_ptr != nullptr);
@ -2026,7 +2026,7 @@ unique_ptr<WebPageBlock> get_web_page_block(Td *td, tl_object_ptr<telegram_api::
auto it = photos.find(page_block->photo_id_);
Photo photo;
if (it != photos.end()) {
photo = it->second;
photo = *it->second;
}
string url;
WebPageId web_page_id;
@ -2076,7 +2076,7 @@ unique_ptr<WebPageBlock> get_web_page_block(Td *td, tl_object_ptr<telegram_api::
: photos.end();
Photo poster_photo;
if (it != photos.end()) {
poster_photo = it->second;
poster_photo = *it->second;
}
Dimensions dimensions;
if (has_dimensions) {
@ -2091,7 +2091,7 @@ unique_ptr<WebPageBlock> get_web_page_block(Td *td, tl_object_ptr<telegram_api::
auto it = photos.find(page_block->author_photo_id_);
Photo author_photo;
if (it != photos.end()) {
author_photo = it->second;
author_photo = *it->second;
}
return td::make_unique<WebPageBlockEmbeddedPost>(
std::move(page_block->url_), std::move(page_block->author_), std::move(author_photo), page_block->date_,
@ -2215,7 +2215,7 @@ unique_ptr<WebPageBlock> get_web_page_block(Td *td, tl_object_ptr<telegram_api::
? photos.find(related_article->photo_id_)
: photos.end();
if (it != photos.end()) {
article.photo = it->second;
article.photo = *it->second;
}
article.author = std::move(related_article->author_);
if ((related_article->flags_ & telegram_api::pageRelatedArticle::PUBLISHED_DATE_MASK) != 0) {
@ -2370,7 +2370,7 @@ void parse(unique_ptr<WebPageBlock> &block, LogEventParser &parser) {
vector<unique_ptr<WebPageBlock>> get_web_page_blocks(
Td *td, vector<tl_object_ptr<telegram_api::PageBlock>> page_block_ptrs,
const FlatHashMap<int64, FileId> &animations, const FlatHashMap<int64, FileId> &audios,
const FlatHashMap<int64, FileId> &documents, const FlatHashMap<int64, Photo> &photos,
const FlatHashMap<int64, FileId> &documents, const FlatHashMap<int64, unique_ptr<Photo>> &photos,
const FlatHashMap<int64, FileId> &videos, const FlatHashMap<int64, FileId> &voice_notes) {
vector<unique_ptr<WebPageBlock>> result;
result.reserve(page_block_ptrs.size());

View File

@ -98,7 +98,7 @@ void parse(unique_ptr<WebPageBlock> &block, LogEventParser &parser);
vector<unique_ptr<WebPageBlock>> get_web_page_blocks(
Td *td, vector<tl_object_ptr<telegram_api::PageBlock>> page_block_ptrs,
const FlatHashMap<int64, FileId> &animations, const FlatHashMap<int64, FileId> &audios,
const FlatHashMap<int64, FileId> &documents, const FlatHashMap<int64, Photo> &photos,
const FlatHashMap<int64, FileId> &documents, const FlatHashMap<int64, unique_ptr<Photo>> &photos,
const FlatHashMap<int64, FileId> &videos, const FlatHashMap<int64, FileId> &voice_notes);
vector<td_api::object_ptr<td_api::PageBlock>> get_page_block_objects(

View File

@ -1407,18 +1407,18 @@ void WebPagesManager::on_pending_web_page_timeout(WebPageId web_page_id) {
void WebPagesManager::on_get_web_page_instant_view(WebPage *web_page, tl_object_ptr<telegram_api::page> &&page,
int32 hash, DialogId owner_dialog_id) {
CHECK(page != nullptr);
FlatHashMap<int64, Photo> photos;
FlatHashMap<int64, unique_ptr<Photo>> photos;
for (auto &photo_ptr : page->photos_) {
Photo photo = get_photo(td_->file_manager_.get(), std::move(photo_ptr), owner_dialog_id);
if (photo.is_empty() || photo.id.get() == 0) {
LOG(ERROR) << "Receive empty photo in web page instant view for " << web_page->url;
} else {
auto photo_id = photo.id.get();
photos.emplace(photo_id, std::move(photo));
photos.emplace(photo_id, make_unique<Photo>(std::move(photo)));
}
}
if (!web_page->photo.is_empty() && web_page->photo.id.get() != 0) {
photos.emplace(web_page->photo.id.get(), web_page->photo);
photos.emplace(web_page->photo.id.get(), make_unique<Photo>(web_page->photo));
}
FlatHashMap<int64, FileId> animations;

View File

@ -237,13 +237,17 @@ class CliClient final : public Actor {
string username;
};
FlatHashMap<int64, User> users_;
FlatHashMap<int64, unique_ptr<User>> users_;
FlatHashMap<string, int64> username_to_user_id_;
vector<string> authentication_tokens_;
void register_user(const td_api::user &user) {
User &new_user = users_[user.id_];
auto &new_user_ptr = users_[user.id_];
if (new_user_ptr == nullptr) {
new_user_ptr = make_unique<User>();
}
User &new_user = *new_user_ptr;
new_user.first_name = user.first_name_;
new_user.last_name = user.last_name_;
new_user.username = user.username_;
@ -253,7 +257,8 @@ class CliClient final : public Actor {
}
void print_user(Logger &log, int64 user_id, bool full = false) {
const User *user = &users_[user_id];
const User *user = users_[user_id].get();
CHECK(user != nullptr);
log << user->first_name << " " << user->last_name << " #" << user_id;
if (!user->username.empty()) {
log << " @" << user->username;

View File

@ -148,7 +148,11 @@ void GetHostByNameActor::run(string host, int port, bool prefer_ipv6, Promise<IP
return promise.set_result(value.get_ip_port(port));
}
auto &query = active_queries_[prefer_ipv6][ascii_host];
auto &query_ptr = active_queries_[prefer_ipv6][ascii_host];
if (query_ptr == nullptr) {
query_ptr = make_unique<Query>();
}
auto &query = *query_ptr;
query.promises.emplace_back(port, std::move(promise));
if (query.query.empty()) {
CHECK(query.promises.size() == 1);
@ -184,7 +188,7 @@ void GetHostByNameActor::run_query(std::string host, bool prefer_ipv6, Query &qu
void GetHostByNameActor::on_query_result(std::string host, bool prefer_ipv6, Result<IPAddress> result) {
auto query_it = active_queries_[prefer_ipv6].find(host);
CHECK(query_it != active_queries_[prefer_ipv6].end());
auto &query = query_it->second;
auto &query = *query_it->second;
CHECK(!query.promises.empty());
CHECK(!query.query.empty());

View File

@ -65,7 +65,7 @@ class GetHostByNameActor final : public Actor {
double begin_time = 0.0;
std::vector<std::pair<int, Promise<IPAddress>>> promises;
};
FlatHashMap<string, Query> active_queries_[2];
FlatHashMap<string, unique_ptr<Query>> active_queries_[2];
Options options_;

View File

@ -40,7 +40,7 @@ TEST(FlatHashMap, basic) {
auto map_copy = map;
}
td::FlatHashMap<int, std::array<td::unique_ptr<td::string>, 20>> x;
td::FlatHashMap<int, std::array<td::unique_ptr<td::string>, 10>> x;
auto y = std::move(x);
x[12];
x.erase(x.find(12));