Use table_remove_if.

This commit is contained in:
levlam 2022-02-10 12:23:52 +03:00
parent 9e6d106585
commit f5d8e4de83
3 changed files with 16 additions and 27 deletions

View File

@ -3442,15 +3442,8 @@ void ContactsManager::on_channel_participant_cache_timeout(ChannelId channel_id)
auto &participants = channel_participants_it->second.participants_;
auto min_access_date = G()->unix_time() - CHANNEL_PARTICIPANT_CACHE_TIME;
vector<DialogId> to_delete_dialog_ids;
for (auto it = participants.begin(); it != participants.end(); ++it) {
if (it->second.last_access_date_ < min_access_date) {
to_delete_dialog_ids.push_back(it->first);
}
}
for (auto dialog_id : to_delete_dialog_ids) {
participants.erase(dialog_id);
}
table_remove_if(participants,
[min_access_date](const auto &it) { return it.second.last_access_date_ < min_access_date; });
if (participants.empty()) {
channel_participants_.erase(channel_participants_it);

View File

@ -112,21 +112,17 @@ void FileStats::apply_dialog_ids(const vector<DialogId> &dialog_ids) {
std::unordered_set<DialogId, DialogIdHash> all_dialogs(dialog_ids.begin(), dialog_ids.end());
StatByType other_stats;
bool other_flag = false;
std::vector<DialogId> to_remove;
for (auto it = stat_by_owner_dialog_id_.begin(); it != stat_by_owner_dialog_id_.end(); ++it) {
if (!all_dialogs.count(it->first)) {
table_remove_if(stat_by_owner_dialog_id_, [&](const auto &it) {
if (!all_dialogs.count(it.first)) {
for (int32 i = 0; i < MAX_FILE_TYPE; i++) {
other_stats[i].size += it->second[i].size;
other_stats[i].cnt += it->second[i].cnt;
other_stats[i].size += it.second[i].size;
other_stats[i].cnt += it.second[i].cnt;
}
other_flag = true;
to_remove.push_back(it->first);
return true;
}
}
for (auto id : to_remove) {
stat_by_owner_dialog_id_.erase(id);
}
return false;
});
if (other_flag) {
DialogId other_dialog_id; // prevents MSVC warning C4709: comma operator within array index expression

View File

@ -13,6 +13,7 @@
#include "td/actor/PromiseFuture.h"
#include "td/utils/algorithm.h"
#include "td/utils/buffer.h"
#include "td/utils/common.h"
#include "td/utils/logging.h"
@ -215,14 +216,13 @@ class BinlogKeyValue final : public KeyValueSyncInterface {
void erase_by_prefix(Slice prefix) final {
auto lock = rw_mutex_.lock_write().move_as_ok();
vector<uint64> ids;
for (auto it = map_.begin(); it != map_.end();) {
if (begins_with(it->first, prefix)) {
ids.push_back(it->second.second);
it = map_.erase(it);
} else {
++it;
table_remove_if(map_, [&](const auto &it) {
if (begins_with(it.first, prefix)) {
ids.push_back(it.second.second);
return true;
}
}
return false;
});
auto seq_no = binlog_->next_id(narrow_cast<int32>(ids.size()));
lock.reset();
for (auto id : ids) {