Minor improvements.

This commit is contained in:
levlam 2023-10-28 00:06:56 +03:00
parent 7097b2bf5b
commit 9c9c1bb51c
4 changed files with 9 additions and 7 deletions

View File

@ -110,7 +110,7 @@ vector<DcOptionsSet::ConnectionInfo> DcOptionsSet::find_all_connections(DcId dc_
if (!static_options.empty()) { if (!static_options.empty()) {
options = std::move(static_options); options = std::move(static_options);
} else { } else {
bool have_ipv4 = td::any_of(options, [](const auto &v) { return !v.option->is_ipv6(); }); bool have_ipv4 = any_of(options, [](const auto &v) { return !v.option->is_ipv6(); });
if (have_ipv4) { if (have_ipv4) {
td::remove_if(options, [](auto &v) { return v.option->is_ipv6(); }); td::remove_if(options, [](auto &v) { return v.option->is_ipv6(); });
} }
@ -122,13 +122,13 @@ vector<DcOptionsSet::ConnectionInfo> DcOptionsSet::find_all_connections(DcId dc_
} }
if (prefer_ipv6) { if (prefer_ipv6) {
bool have_ipv6 = td::any_of(options, [](const auto &v) { return v.option->is_ipv6(); }); bool have_ipv6 = any_of(options, [](const auto &v) { return v.option->is_ipv6(); });
if (have_ipv6) { if (have_ipv6) {
td::remove_if(options, [](auto &v) { return !v.option->is_ipv6(); }); td::remove_if(options, [](auto &v) { return !v.option->is_ipv6(); });
} }
} }
bool have_media_only = td::any_of(options, [](const auto &v) { return v.option->is_media_only(); }); bool have_media_only = any_of(options, [](const auto &v) { return v.option->is_media_only(); });
if (have_media_only) { if (have_media_only) {
td::remove_if(options, [](auto &v) { return !v.option->is_media_only(); }); td::remove_if(options, [](auto &v) { return !v.option->is_media_only(); });
} }

View File

@ -15,6 +15,7 @@
#include "td/utils/buffer.h" #include "td/utils/buffer.h"
#include "td/utils/common.h" #include "td/utils/common.h"
#include "td/utils/FlatHashMap.h" #include "td/utils/FlatHashMap.h"
#include "td/utils/HashTableUtils.h"
#include "td/utils/logging.h" #include "td/utils/logging.h"
#include "td/utils/misc.h" #include "td/utils/misc.h"
#include "td/utils/port/RwMutex.h" #include "td/utils/port/RwMutex.h"
@ -219,9 +220,9 @@ class BinlogKeyValue final : public KeyValueSyncInterface {
binlog_->lazy_sync(std::move(promise)); binlog_->lazy_sync(std::move(promise));
} }
std::unordered_map<string, string> prefix_get(Slice prefix) final { std::unordered_map<string, string, Hash<string>> prefix_get(Slice prefix) final {
auto lock = rw_mutex_.lock_write().move_as_ok(); auto lock = rw_mutex_.lock_write().move_as_ok();
std::unordered_map<string, string> res; std::unordered_map<string, string, Hash<string>> res;
for (const auto &kv : map_) { for (const auto &kv : map_) {
if (begins_with(kv.first, prefix)) { if (begins_with(kv.first, prefix)) {
res.emplace(kv.first.substr(prefix.size()), kv.second.first); res.emplace(kv.first.substr(prefix.size()), kv.second.first);

View File

@ -8,6 +8,7 @@
#include "td/utils/common.h" #include "td/utils/common.h"
#include "td/utils/FlatHashMap.h" #include "td/utils/FlatHashMap.h"
#include "td/utils/HashTableUtils.h"
#include "td/utils/Promise.h" #include "td/utils/Promise.h"
#include "td/utils/Slice.h" #include "td/utils/Slice.h"
@ -34,7 +35,7 @@ class KeyValueSyncInterface {
virtual string get(const string &key) = 0; virtual string get(const string &key) = 0;
virtual std::unordered_map<string, string> prefix_get(Slice prefix) = 0; virtual std::unordered_map<string, string, Hash<string>> prefix_get(Slice prefix) = 0;
virtual FlatHashMap<string, string> get_all() = 0; virtual FlatHashMap<string, string> get_all() = 0;

View File

@ -12,7 +12,7 @@
namespace td { namespace td {
// More strict implementaions of flood control than FloodControlFast. // More strict implementations of flood control than FloodControlFast.
// Should be just fine for small counters. // Should be just fine for small counters.
class FloodControlStrict { class FloodControlStrict {
public: public: