Use td::remove_if.

GitOrigin-RevId: 5cf21381966dc58689a06cc94cb8843fd8087bb9
This commit is contained in:
levlam 2019-10-21 16:25:56 +03:00
parent cc0a2eeb99
commit 56c3a2fbed
13 changed files with 74 additions and 101 deletions

View File

@ -468,9 +468,7 @@ ActorOwn<> get_full_config(DcOption option, Promise<FullConfig> promise, ActorSh
std::vector<unique_ptr<Listener>> auth_key_listeners_;
void notify() {
auto it = std::remove_if(auth_key_listeners_.begin(), auth_key_listeners_.end(),
[&](auto &listener) { return !listener->notify(); });
auth_key_listeners_.erase(it, auth_key_listeners_.end());
td::remove_if(auth_key_listeners_, [&](auto &listener) { return !listener->notify(); });
}
string auth_key_key() const {

View File

@ -985,15 +985,13 @@ const std::unordered_set<Slice, SliceHash> &get_valid_short_usernames() {
vector<Slice> find_mentions(Slice str) {
auto mentions = match_mentions(str);
mentions.erase(std::remove_if(mentions.begin(), mentions.end(),
[](Slice mention) {
td::remove_if(mentions, [](Slice mention) {
mention.remove_prefix(1);
if (mention.size() >= 5) {
return false;
}
return get_valid_short_usernames().count(mention) == 0;
}),
mentions.end());
});
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(current_entity == entities.size());
entities.erase(
std::remove_if(entities.begin(), entities.end(), [](const auto &entity) { return entity.length == 0; }),
entities.end());
td::remove_if(entities, [](const auto &entity) { return entity.length == 0; });
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);
entities.erase(
std::remove_if(entities.begin(), entities.end(),
[text_utf16_length = narrow_cast<int32>(utf8_utf16_length(text))](const auto &entity) {
td::remove_if(entities, [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) {

View File

@ -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) {
dialog_ids.erase(std::remove_if(dialog_ids.begin(), dialog_ids.end(),
[](DialogId dialog_id) { return dialog_id.get_type() == DialogType::SecretChat; }),
dialog_ids.end());
td::remove_if(dialog_ids, [](DialogId dialog_id) { return dialog_id.get_type() == DialogType::SecretChat; });
return dialog_ids;
}

View File

@ -4873,15 +4873,13 @@ void StickersManager::on_get_language_codes(const string &key, Result<vector<str
auto language_codes = result.move_as_ok();
LOG(INFO) << "Receive language codes " << language_codes << " for emojis search";
language_codes.erase(std::remove_if(language_codes.begin(), language_codes.end(),
[](const auto &language_code) {
td::remove_if(language_codes, [](const auto &language_code) {
if (language_code.empty() || language_code.find('$') != string::npos) {
LOG(ERROR) << "Receive language_code \"" << language_code << '"';
return true;
}
return false;
}),
language_codes.end());
});
if (language_codes.empty()) {
LOG(ERROR) << "Language codes list is empty";
language_codes.emplace_back("en");

View File

@ -1273,7 +1273,7 @@ class CliClient final : public Actor {
void on_cmd(string 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 << "]";
string op;

View File

@ -94,10 +94,7 @@ void FileGcWorker::run_gc(const FileGcParameters &parameters, std::vector<FullFi
// Remove all files with atime > now - max_time_from_last_access
double now = Clocks::system();
files.erase(
std::remove_if(
files.begin(), files.end(),
[&](const FullFileInfo &info) {
td::remove_if(files, [&](const FullFileInfo &info) {
if (token_) {
return false;
}
@ -113,8 +110,8 @@ void FileGcWorker::run_gc(const FileGcParameters &parameters, std::vector<FullFi
return true;
}
if (!parameters.owner_dialog_ids.empty() &&
std::find(parameters.owner_dialog_ids.begin(), parameters.owner_dialog_ids.end(),
info.owner_dialog_id) == parameters.owner_dialog_ids.end()) {
std::find(parameters.owner_dialog_ids.begin(), parameters.owner_dialog_ids.end(), info.owner_dialog_id) ==
parameters.owner_dialog_ids.end()) {
owner_dialog_id_ignored_cnt++;
new_stats.add(FullFileInfo(info));
return true;
@ -133,8 +130,7 @@ void FileGcWorker::run_gc(const FileGcParameters &parameters, std::vector<FullFi
return true;
}
return false;
}),
files.end());
});
if (token_) {
return promise.set_error(Status::Error(500, "Request aborted"));
}

View File

@ -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);
bad_parts.erase(std::remove_if(bad_parts.begin(), bad_parts.end(), [](auto part_id) { return part_id < 0; }),
bad_parts.end());
td::remove_if(bad_parts, [](auto part_id) { return part_id < 0; });
QueryId id = queries_container_.create(Query{file_id, Query::Upload});
node->upload_id_ = id;

View File

@ -11,11 +11,10 @@
#include "td/utils/format.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"
#include "td/utils/port/RwMutex.h"
#include "td/utils/tl_helpers.h"
#include <algorithm>
namespace td {
class AuthDataSharedImpl : public AuthDataShared {
@ -103,9 +102,7 @@ class AuthDataSharedImpl : public AuthDataShared {
void notify() {
auto lock = rw_mutex_.lock_read();
auto it = std::remove_if(auth_key_listeners_.begin(), auth_key_listeners_.end(),
[&](auto &listener) { return !listener->notify(); });
auth_key_listeners_.erase(it, auth_key_listeners_.end());
td::remove_if(auth_key_listeners_, [&](auto &listener) { return !listener->notify(); });
}
void log_auth_key(const mtproto::AuthKey &auth_key) {

View File

@ -812,14 +812,12 @@ void ConnectionCreator::client_loop(ClientInfo &client) {
VLOG(connections) << "In client_loop: " << tag("client", format::as_hex(client.hash));
// Remove expired ready connections
client.ready_connections.erase(
std::remove_if(client.ready_connections.begin(), client.ready_connections.end(),
td::remove_if(client.ready_connections,
[&, expires_at = Time::now_cached() - ClientInfo::READY_CONNECTIONS_TIMEOUT](auto &v) {
bool drop = v.second < expires_at;
VLOG_IF(connections, drop) << "Drop expired " << tag("connection", v.first.get());
return drop;
}),
client.ready_connections.end());
});
// Send ready connections into promises
{

View File

@ -8,6 +8,7 @@
#include "td/utils/format.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"
#include <algorithm>
#include <set>
@ -98,8 +99,7 @@ vector<DcOptionsSet::ConnectionInfo> DcOptionsSet::find_all_connections(DcId dc_
} else {
bool have_ipv4 = std::any_of(options.begin(), options.end(), [](auto &v) { return !v.option->is_ipv6(); });
if (have_ipv4) {
options.erase(std::remove_if(options.begin(), options.end(), [](auto &v) { return v.option->is_ipv6(); }),
options.end());
td::remove_if(options, [](auto &v) { return v.option->is_ipv6(); });
}
}
} else {
@ -111,15 +111,13 @@ vector<DcOptionsSet::ConnectionInfo> DcOptionsSet::find_all_connections(DcId dc_
if (prefer_ipv6) {
bool have_ipv6 = std::any_of(options.begin(), options.end(), [](auto &v) { return v.option->is_ipv6(); });
if (have_ipv6) {
options.erase(std::remove_if(options.begin(), options.end(), [](auto &v) { return !v.option->is_ipv6(); }),
options.end());
td::remove_if(options, [](auto &v) { return !v.option->is_ipv6(); });
}
}
bool have_media_only = std::any_of(options.begin(), options.end(), [](auto &v) { return v.option->is_media_only(); });
if (have_media_only) {
options.erase(std::remove_if(options.begin(), options.end(), [](auto &v) { return !v.option->is_media_only(); }),
options.end());
td::remove_if(options, [](auto &v) { return !v.option->is_media_only(); });
}
return options;

View File

@ -8,6 +8,7 @@
#include "td/utils/format.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"
@ -153,8 +154,7 @@ RSA *PublicRsaKeyShared::get_rsa_locked(int64 fingerprint) {
void PublicRsaKeyShared::notify() {
auto lock = rw_mutex_.lock_read();
auto it = std::remove_if(listeners_.begin(), listeners_.end(), [&](auto &listener) { return !listener->notify(); });
listeners_.erase(it, listeners_.end());
td::remove_if(listeners_, [&](auto &listener) { return !listener->notify(); });
}
} // namespace td

View File

@ -34,7 +34,6 @@
#include "td/utils/Timer.h"
#include "td/utils/tl_parsers.h"
#include <algorithm>
#include <tuple>
#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) {
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);
if (it == sent_queries_.end()) {
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;
return false;
});
msg_ids.erase(erase_from, msg_ids.end());
if (msg_ids.empty()) {
return;
}

View File

@ -84,7 +84,7 @@ auto transform(T &&v, const Func &f) {
}
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;
while (i != v.size() && !f(v[i])) {
i++;