Optimize NotificationManager::get_group.

GitOrigin-RevId: 0b0ae8d0ad274b1c91868943449d09e17aff25f7
This commit is contained in:
levlam 2018-12-02 23:28:24 +03:00
parent 7ce70d8056
commit 7bdad0c877
2 changed files with 8 additions and 5 deletions

View File

@ -156,15 +156,15 @@ void NotificationManager::tear_down() {
NotificationManager::NotificationGroups::iterator NotificationManager::add_group(NotificationGroupKey &&group_key,
NotificationGroup &&group) {
bool is_inserted = group_keys_.emplace(group_key.group_id, group_key).second;
CHECK(is_inserted);
return groups_.emplace(std::move(group_key), std::move(group)).first;
}
NotificationManager::NotificationGroups::iterator NotificationManager::get_group(NotificationGroupId group_id) {
// TODO optimize
for (auto it = groups_.begin(); it != groups_.end(); ++it) {
if (it->first.group_id == group_id) {
return it;
}
auto group_keys_it = group_keys_.find(group_id);
if (group_keys_it != group_keys_.end()) {
return groups_.find(group_keys_it->second);
}
return groups_.end();
}
@ -207,6 +207,8 @@ NotificationManager::NotificationGroups::iterator NotificationManager::get_group
}
void NotificationManager::delete_group(NotificationGroups::iterator &&group_it) {
bool is_erased = group_keys_.erase(group_it->first.group_id);
CHECK(is_erased);
groups_.erase(group_it);
}

View File

@ -186,6 +186,7 @@ class NotificationManager : public Actor {
std::unordered_set<int32> running_get_chat_difference_;
NotificationGroups groups_;
std::unordered_map<NotificationGroupId, NotificationGroupKey, NotificationGroupIdHash> group_keys_;
std::unordered_map<int32, vector<td_api::object_ptr<td_api::Update>>> pending_updates_;