Use td::remove_if.
GitOrigin-RevId: 5cf21381966dc58689a06cc94cb8843fd8087bb9
This commit is contained in:
parent
cc0a2eeb99
commit
56c3a2fbed
@ -468,9 +468,7 @@ ActorOwn<> get_full_config(DcOption option, Promise<FullConfig> promise, ActorSh
|
|||||||
|
|
||||||
std::vector<unique_ptr<Listener>> auth_key_listeners_;
|
std::vector<unique_ptr<Listener>> auth_key_listeners_;
|
||||||
void notify() {
|
void notify() {
|
||||||
auto it = std::remove_if(auth_key_listeners_.begin(), auth_key_listeners_.end(),
|
td::remove_if(auth_key_listeners_, [&](auto &listener) { return !listener->notify(); });
|
||||||
[&](auto &listener) { return !listener->notify(); });
|
|
||||||
auth_key_listeners_.erase(it, auth_key_listeners_.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string auth_key_key() const {
|
string auth_key_key() const {
|
||||||
|
@ -985,15 +985,13 @@ const std::unordered_set<Slice, SliceHash> &get_valid_short_usernames() {
|
|||||||
|
|
||||||
vector<Slice> find_mentions(Slice str) {
|
vector<Slice> find_mentions(Slice str) {
|
||||||
auto mentions = match_mentions(str);
|
auto mentions = match_mentions(str);
|
||||||
mentions.erase(std::remove_if(mentions.begin(), mentions.end(),
|
td::remove_if(mentions, [](Slice mention) {
|
||||||
[](Slice mention) {
|
mention.remove_prefix(1);
|
||||||
mention.remove_prefix(1);
|
if (mention.size() >= 5) {
|
||||||
if (mention.size() >= 5) {
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
return get_valid_short_usernames().count(mention) == 0;
|
||||||
return get_valid_short_usernames().count(mention) == 0;
|
});
|
||||||
}),
|
|
||||||
mentions.end());
|
|
||||||
return mentions;
|
return mentions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2572,9 +2570,7 @@ static std::pair<size_t, int32> remove_invalid_entities(const string &text, vect
|
|||||||
CHECK(nested_entities_stack.empty());
|
CHECK(nested_entities_stack.empty());
|
||||||
CHECK(current_entity == entities.size());
|
CHECK(current_entity == entities.size());
|
||||||
|
|
||||||
entities.erase(
|
td::remove_if(entities, [](const auto &entity) { return entity.length == 0; });
|
||||||
std::remove_if(entities.begin(), entities.end(), [](const auto &entity) { return entity.length == 0; }),
|
|
||||||
entities.end());
|
|
||||||
|
|
||||||
return {last_non_whitespace_pos, last_non_whitespace_utf16_offset};
|
return {last_non_whitespace_pos, last_non_whitespace_utf16_offset};
|
||||||
}
|
}
|
||||||
@ -2651,12 +2647,9 @@ Status fix_formatted_text(string &text, vector<MessageEntity> &entities, bool al
|
|||||||
}
|
}
|
||||||
text.resize(new_size);
|
text.resize(new_size);
|
||||||
|
|
||||||
entities.erase(
|
td::remove_if(entities, [text_utf16_length = narrow_cast<int32>(utf8_utf16_length(text))](const auto &entity) {
|
||||||
std::remove_if(entities.begin(), entities.end(),
|
return entity.offset + entity.length > text_utf16_length;
|
||||||
[text_utf16_length = narrow_cast<int32>(utf8_utf16_length(text))](const auto &entity) {
|
});
|
||||||
return entity.offset + entity.length > text_utf16_length;
|
|
||||||
}),
|
|
||||||
entities.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!skip_new_entities) {
|
if (!skip_new_entities) {
|
||||||
|
@ -13476,9 +13476,7 @@ int32 MessagesManager::get_pinned_dialogs_limit(FolderId folder_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vector<DialogId> MessagesManager::remove_secret_chat_dialog_ids(vector<DialogId> dialog_ids) {
|
vector<DialogId> MessagesManager::remove_secret_chat_dialog_ids(vector<DialogId> dialog_ids) {
|
||||||
dialog_ids.erase(std::remove_if(dialog_ids.begin(), dialog_ids.end(),
|
td::remove_if(dialog_ids, [](DialogId dialog_id) { return dialog_id.get_type() == DialogType::SecretChat; });
|
||||||
[](DialogId dialog_id) { return dialog_id.get_type() == DialogType::SecretChat; }),
|
|
||||||
dialog_ids.end());
|
|
||||||
return dialog_ids;
|
return dialog_ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4873,15 +4873,13 @@ void StickersManager::on_get_language_codes(const string &key, Result<vector<str
|
|||||||
|
|
||||||
auto language_codes = result.move_as_ok();
|
auto language_codes = result.move_as_ok();
|
||||||
LOG(INFO) << "Receive language codes " << language_codes << " for emojis search";
|
LOG(INFO) << "Receive language codes " << language_codes << " for emojis search";
|
||||||
language_codes.erase(std::remove_if(language_codes.begin(), language_codes.end(),
|
td::remove_if(language_codes, [](const auto &language_code) {
|
||||||
[](const auto &language_code) {
|
if (language_code.empty() || language_code.find('$') != string::npos) {
|
||||||
if (language_code.empty() || language_code.find('$') != string::npos) {
|
LOG(ERROR) << "Receive language_code \"" << language_code << '"';
|
||||||
LOG(ERROR) << "Receive language_code \"" << language_code << '"';
|
return true;
|
||||||
return true;
|
}
|
||||||
}
|
return false;
|
||||||
return false;
|
});
|
||||||
}),
|
|
||||||
language_codes.end());
|
|
||||||
if (language_codes.empty()) {
|
if (language_codes.empty()) {
|
||||||
LOG(ERROR) << "Language codes list is empty";
|
LOG(ERROR) << "Language codes list is empty";
|
||||||
language_codes.emplace_back("en");
|
language_codes.emplace_back("en");
|
||||||
|
@ -1273,7 +1273,7 @@ class CliClient final : public Actor {
|
|||||||
|
|
||||||
void on_cmd(string cmd) {
|
void on_cmd(string cmd) {
|
||||||
// TODO: need to remove https://en.wikipedia.org/wiki/ANSI_escape_code from cmd
|
// TODO: need to remove https://en.wikipedia.org/wiki/ANSI_escape_code from cmd
|
||||||
cmd.erase(std::remove_if(cmd.begin(), cmd.end(), [](unsigned char c) { return c < 32; }), cmd.end());
|
td::remove_if(cmd, [](unsigned char c) { return c < 32; });
|
||||||
LOG(INFO) << "CMD:[" << cmd << "]";
|
LOG(INFO) << "CMD:[" << cmd << "]";
|
||||||
|
|
||||||
string op;
|
string op;
|
||||||
|
@ -94,47 +94,43 @@ void FileGcWorker::run_gc(const FileGcParameters ¶meters, std::vector<FullFi
|
|||||||
|
|
||||||
// Remove all files with atime > now - max_time_from_last_access
|
// Remove all files with atime > now - max_time_from_last_access
|
||||||
double now = Clocks::system();
|
double now = Clocks::system();
|
||||||
files.erase(
|
td::remove_if(files, [&](const FullFileInfo &info) {
|
||||||
std::remove_if(
|
if (token_) {
|
||||||
files.begin(), files.end(),
|
return false;
|
||||||
[&](const FullFileInfo &info) {
|
}
|
||||||
if (token_) {
|
if (immune_types[narrow_cast<size_t>(info.file_type)]) {
|
||||||
return false;
|
type_immunity_ignored_cnt++;
|
||||||
}
|
new_stats.add(FullFileInfo(info));
|
||||||
if (immune_types[narrow_cast<size_t>(info.file_type)]) {
|
return true;
|
||||||
type_immunity_ignored_cnt++;
|
}
|
||||||
new_stats.add(FullFileInfo(info));
|
if (std::find(parameters.exclude_owner_dialog_ids.begin(), parameters.exclude_owner_dialog_ids.end(),
|
||||||
return true;
|
info.owner_dialog_id) != parameters.exclude_owner_dialog_ids.end()) {
|
||||||
}
|
exclude_owner_dialog_id_ignored_cnt++;
|
||||||
if (std::find(parameters.exclude_owner_dialog_ids.begin(), parameters.exclude_owner_dialog_ids.end(),
|
new_stats.add(FullFileInfo(info));
|
||||||
info.owner_dialog_id) != parameters.exclude_owner_dialog_ids.end()) {
|
return true;
|
||||||
exclude_owner_dialog_id_ignored_cnt++;
|
}
|
||||||
new_stats.add(FullFileInfo(info));
|
if (!parameters.owner_dialog_ids.empty() &&
|
||||||
return true;
|
std::find(parameters.owner_dialog_ids.begin(), parameters.owner_dialog_ids.end(), info.owner_dialog_id) ==
|
||||||
}
|
parameters.owner_dialog_ids.end()) {
|
||||||
if (!parameters.owner_dialog_ids.empty() &&
|
owner_dialog_id_ignored_cnt++;
|
||||||
std::find(parameters.owner_dialog_ids.begin(), parameters.owner_dialog_ids.end(),
|
new_stats.add(FullFileInfo(info));
|
||||||
info.owner_dialog_id) == parameters.owner_dialog_ids.end()) {
|
return true;
|
||||||
owner_dialog_id_ignored_cnt++;
|
}
|
||||||
new_stats.add(FullFileInfo(info));
|
if (static_cast<double>(info.mtime_nsec / 1000000000) > now - parameters.immunity_delay) {
|
||||||
return true;
|
// new files are immune to gc
|
||||||
}
|
time_immunity_ignored_cnt++;
|
||||||
if (static_cast<double>(info.mtime_nsec / 1000000000) > now - parameters.immunity_delay) {
|
new_stats.add(FullFileInfo(info));
|
||||||
// new files are immune to gc
|
return true;
|
||||||
time_immunity_ignored_cnt++;
|
}
|
||||||
new_stats.add(FullFileInfo(info));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (static_cast<double>(info.atime_nsec / 1000000000) < now - parameters.max_time_from_last_access) {
|
if (static_cast<double>(info.atime_nsec / 1000000000) < now - parameters.max_time_from_last_access) {
|
||||||
do_remove_file(info);
|
do_remove_file(info);
|
||||||
total_removed_size += info.size;
|
total_removed_size += info.size;
|
||||||
remove_by_atime_cnt++;
|
remove_by_atime_cnt++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}),
|
});
|
||||||
files.end());
|
|
||||||
if (token_) {
|
if (token_) {
|
||||||
return promise.set_error(Status::Error(500, "Request aborted"));
|
return promise.set_error(Status::Error(500, "Request aborted"));
|
||||||
}
|
}
|
||||||
|
@ -2638,8 +2638,7 @@ void FileManager::run_upload(FileNodePtr node, std::vector<int> bad_parts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto new_priority = narrow_cast<int8>(bad_parts.empty() ? -priority : priority);
|
auto new_priority = narrow_cast<int8>(bad_parts.empty() ? -priority : priority);
|
||||||
bad_parts.erase(std::remove_if(bad_parts.begin(), bad_parts.end(), [](auto part_id) { return part_id < 0; }),
|
td::remove_if(bad_parts, [](auto part_id) { return part_id < 0; });
|
||||||
bad_parts.end());
|
|
||||||
|
|
||||||
QueryId id = queries_container_.create(Query{file_id, Query::Upload});
|
QueryId id = queries_container_.create(Query{file_id, Query::Upload});
|
||||||
node->upload_id_ = id;
|
node->upload_id_ = id;
|
||||||
|
@ -11,11 +11,10 @@
|
|||||||
|
|
||||||
#include "td/utils/format.h"
|
#include "td/utils/format.h"
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
|
#include "td/utils/misc.h"
|
||||||
#include "td/utils/port/RwMutex.h"
|
#include "td/utils/port/RwMutex.h"
|
||||||
#include "td/utils/tl_helpers.h"
|
#include "td/utils/tl_helpers.h"
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
class AuthDataSharedImpl : public AuthDataShared {
|
class AuthDataSharedImpl : public AuthDataShared {
|
||||||
@ -103,9 +102,7 @@ class AuthDataSharedImpl : public AuthDataShared {
|
|||||||
void notify() {
|
void notify() {
|
||||||
auto lock = rw_mutex_.lock_read();
|
auto lock = rw_mutex_.lock_read();
|
||||||
|
|
||||||
auto it = std::remove_if(auth_key_listeners_.begin(), auth_key_listeners_.end(),
|
td::remove_if(auth_key_listeners_, [&](auto &listener) { return !listener->notify(); });
|
||||||
[&](auto &listener) { return !listener->notify(); });
|
|
||||||
auth_key_listeners_.erase(it, auth_key_listeners_.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void log_auth_key(const mtproto::AuthKey &auth_key) {
|
void log_auth_key(const mtproto::AuthKey &auth_key) {
|
||||||
|
@ -812,14 +812,12 @@ void ConnectionCreator::client_loop(ClientInfo &client) {
|
|||||||
VLOG(connections) << "In client_loop: " << tag("client", format::as_hex(client.hash));
|
VLOG(connections) << "In client_loop: " << tag("client", format::as_hex(client.hash));
|
||||||
|
|
||||||
// Remove expired ready connections
|
// Remove expired ready connections
|
||||||
client.ready_connections.erase(
|
td::remove_if(client.ready_connections,
|
||||||
std::remove_if(client.ready_connections.begin(), client.ready_connections.end(),
|
[&, expires_at = Time::now_cached() - ClientInfo::READY_CONNECTIONS_TIMEOUT](auto &v) {
|
||||||
[&, expires_at = Time::now_cached() - ClientInfo::READY_CONNECTIONS_TIMEOUT](auto &v) {
|
bool drop = v.second < expires_at;
|
||||||
bool drop = v.second < expires_at;
|
VLOG_IF(connections, drop) << "Drop expired " << tag("connection", v.first.get());
|
||||||
VLOG_IF(connections, drop) << "Drop expired " << tag("connection", v.first.get());
|
return drop;
|
||||||
return drop;
|
});
|
||||||
}),
|
|
||||||
client.ready_connections.end());
|
|
||||||
|
|
||||||
// Send ready connections into promises
|
// Send ready connections into promises
|
||||||
{
|
{
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "td/utils/format.h"
|
#include "td/utils/format.h"
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
|
#include "td/utils/misc.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <set>
|
#include <set>
|
||||||
@ -98,8 +99,7 @@ vector<DcOptionsSet::ConnectionInfo> DcOptionsSet::find_all_connections(DcId dc_
|
|||||||
} else {
|
} else {
|
||||||
bool have_ipv4 = std::any_of(options.begin(), options.end(), [](auto &v) { return !v.option->is_ipv6(); });
|
bool have_ipv4 = std::any_of(options.begin(), options.end(), [](auto &v) { return !v.option->is_ipv6(); });
|
||||||
if (have_ipv4) {
|
if (have_ipv4) {
|
||||||
options.erase(std::remove_if(options.begin(), options.end(), [](auto &v) { return v.option->is_ipv6(); }),
|
td::remove_if(options, [](auto &v) { return v.option->is_ipv6(); });
|
||||||
options.end());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -111,15 +111,13 @@ vector<DcOptionsSet::ConnectionInfo> DcOptionsSet::find_all_connections(DcId dc_
|
|||||||
if (prefer_ipv6) {
|
if (prefer_ipv6) {
|
||||||
bool have_ipv6 = std::any_of(options.begin(), options.end(), [](auto &v) { return v.option->is_ipv6(); });
|
bool have_ipv6 = std::any_of(options.begin(), options.end(), [](auto &v) { return v.option->is_ipv6(); });
|
||||||
if (have_ipv6) {
|
if (have_ipv6) {
|
||||||
options.erase(std::remove_if(options.begin(), options.end(), [](auto &v) { return !v.option->is_ipv6(); }),
|
td::remove_if(options, [](auto &v) { return !v.option->is_ipv6(); });
|
||||||
options.end());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool have_media_only = std::any_of(options.begin(), options.end(), [](auto &v) { return v.option->is_media_only(); });
|
bool have_media_only = std::any_of(options.begin(), options.end(), [](auto &v) { return v.option->is_media_only(); });
|
||||||
if (have_media_only) {
|
if (have_media_only) {
|
||||||
options.erase(std::remove_if(options.begin(), options.end(), [](auto &v) { return !v.option->is_media_only(); }),
|
td::remove_if(options, [](auto &v) { return !v.option->is_media_only(); });
|
||||||
options.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "td/utils/format.h"
|
#include "td/utils/format.h"
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
|
#include "td/utils/misc.h"
|
||||||
#include "td/utils/Slice.h"
|
#include "td/utils/Slice.h"
|
||||||
#include "td/utils/Status.h"
|
#include "td/utils/Status.h"
|
||||||
|
|
||||||
@ -153,8 +154,7 @@ RSA *PublicRsaKeyShared::get_rsa_locked(int64 fingerprint) {
|
|||||||
|
|
||||||
void PublicRsaKeyShared::notify() {
|
void PublicRsaKeyShared::notify() {
|
||||||
auto lock = rw_mutex_.lock_read();
|
auto lock = rw_mutex_.lock_read();
|
||||||
auto it = std::remove_if(listeners_.begin(), listeners_.end(), [&](auto &listener) { return !listener->notify(); });
|
td::remove_if(listeners_, [&](auto &listener) { return !listener->notify(); });
|
||||||
listeners_.erase(it, listeners_.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -34,7 +34,6 @@
|
|||||||
#include "td/utils/Timer.h"
|
#include "td/utils/Timer.h"
|
||||||
#include "td/utils/tl_parsers.h"
|
#include "td/utils/tl_parsers.h"
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
@ -510,7 +509,7 @@ void Session::on_session_failed(Status status) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Session::on_container_sent(uint64 container_id, vector<uint64> msg_ids) {
|
void Session::on_container_sent(uint64 container_id, vector<uint64> msg_ids) {
|
||||||
auto erase_from = std::remove_if(msg_ids.begin(), msg_ids.end(), [&](uint64 msg_id) {
|
td::remove_if(msg_ids, [&](uint64 msg_id) {
|
||||||
auto it = sent_queries_.find(msg_id);
|
auto it = sent_queries_.find(msg_id);
|
||||||
if (it == sent_queries_.end()) {
|
if (it == sent_queries_.end()) {
|
||||||
return true; // remove
|
return true; // remove
|
||||||
@ -518,7 +517,6 @@ void Session::on_container_sent(uint64 container_id, vector<uint64> msg_ids) {
|
|||||||
it->second.container_id = container_id;
|
it->second.container_id = container_id;
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
msg_ids.erase(erase_from, msg_ids.end());
|
|
||||||
if (msg_ids.empty()) {
|
if (msg_ids.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ auto transform(T &&v, const Func &f) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class T, class Func>
|
template <class T, class Func>
|
||||||
void remove_if(vector<T> &v, const Func &f) {
|
void remove_if(T &v, const Func &f) {
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
while (i != v.size() && !f(v[i])) {
|
while (i != v.size() && !f(v[i])) {
|
||||||
i++;
|
i++;
|
||||||
|
Reference in New Issue
Block a user