More FlatHashMap usages.
This commit is contained in:
parent
b4fda2d45a
commit
22ed61e1b7
@ -58,7 +58,7 @@ string ConfigShared::get_option(Slice name) const {
|
||||
return config_pmc_->get(name.str());
|
||||
}
|
||||
|
||||
FlatHashMap<string, string> ConfigShared::get_options() const {
|
||||
std::unordered_map<string, string> ConfigShared::get_options() const {
|
||||
return config_pmc_->get_all();
|
||||
}
|
||||
|
||||
|
@ -9,10 +9,10 @@
|
||||
#include "td/db/KeyValueSyncInterface.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/FlatHashMap.h"
|
||||
#include "td/utils/Slice.h"
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace td {
|
||||
|
||||
@ -42,7 +42,7 @@ class ConfigShared {
|
||||
|
||||
string get_option(Slice name) const;
|
||||
|
||||
FlatHashMap<string, string> get_options() const;
|
||||
std::unordered_map<string, string> get_options() const;
|
||||
|
||||
bool get_option_boolean(Slice name, bool default_value = false) const;
|
||||
int64 get_option_integer(Slice name, int64 default_value = 0) const;
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "td/actor/impl/EventFull-decl.h"
|
||||
|
||||
#include "td/utils/Closure.h"
|
||||
#include "td/utils/FlatHashMap.h"
|
||||
#include "td/utils/Heap.h"
|
||||
#include "td/utils/List.h"
|
||||
#include "td/utils/logging.h"
|
||||
@ -28,7 +29,6 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
|
||||
namespace td {
|
||||
@ -210,7 +210,7 @@ class Scheduler {
|
||||
ListNode ready_actors_list_;
|
||||
KHeap<double> timeout_queue_;
|
||||
|
||||
std::unordered_map<ActorInfo *, std::vector<Event>> pending_events_;
|
||||
FlatHashMap<ActorInfo *, std::vector<Event>> pending_events_;
|
||||
|
||||
ServiceActor service_actor_;
|
||||
Poll poll_;
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
#include "td/utils/buffer.h"
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/FlatHashMap.h"
|
||||
#include "td/utils/logging.h"
|
||||
#include "td/utils/misc.h"
|
||||
#include "td/utils/port/RwMutex.h"
|
||||
@ -193,29 +192,29 @@ class BinlogKeyValue final : public KeyValueSyncInterface {
|
||||
binlog_->lazy_sync(std::move(promise));
|
||||
}
|
||||
|
||||
FlatHashMap<string, string> prefix_get(Slice prefix) final {
|
||||
std::unordered_map<string, string> prefix_get(Slice prefix) final {
|
||||
auto lock = rw_mutex_.lock_write().move_as_ok();
|
||||
FlatHashMap<string, string> res;
|
||||
std::unordered_map<string, string> res;
|
||||
for (const auto &kv : map_) {
|
||||
if (begins_with(kv.first, prefix)) {
|
||||
res[kv.first.substr(prefix.size())] = kv.second.first;
|
||||
res.emplace(kv.first.substr(prefix.size()), kv.second.first);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
FlatHashMap<string, string> get_all() final {
|
||||
std::unordered_map<string, string> get_all() final {
|
||||
auto lock = rw_mutex_.lock_write().move_as_ok();
|
||||
FlatHashMap<string, string> res;
|
||||
std::unordered_map<string, string> res;
|
||||
for (const auto &kv : map_) {
|
||||
res[kv.first] = kv.second.first;
|
||||
res.emplace(kv.first, kv.second.first);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void erase_by_prefix(Slice prefix) final {
|
||||
auto lock = rw_mutex_.lock_write().move_as_ok();
|
||||
std::vector<uint64> ids;
|
||||
vector<uint64> ids;
|
||||
for (auto it = map_.begin(); it != map_.end();) {
|
||||
if (begins_with(it->first, prefix)) {
|
||||
ids.push_back(it->second.second);
|
||||
|
@ -9,9 +9,10 @@
|
||||
#include "td/actor/PromiseFuture.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/FlatHashMap.h"
|
||||
#include "td/utils/Slice.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace td {
|
||||
|
||||
class KeyValueSyncInterface {
|
||||
@ -33,9 +34,9 @@ class KeyValueSyncInterface {
|
||||
|
||||
virtual string get(const string &key) = 0;
|
||||
|
||||
virtual FlatHashMap<string, string> prefix_get(Slice prefix) = 0;
|
||||
virtual std::unordered_map<string, string> prefix_get(Slice prefix) = 0;
|
||||
|
||||
virtual FlatHashMap<string, string> get_all() = 0;
|
||||
virtual std::unordered_map<string, string> get_all() = 0;
|
||||
|
||||
virtual SeqNo erase(const string &key) = 0;
|
||||
|
||||
|
@ -121,15 +121,14 @@ GetHostByNameActor::GetHostByNameActor(Options options) : options_(std::move(opt
|
||||
}
|
||||
|
||||
void GetHostByNameActor::run(string host, int port, bool prefer_ipv6, Promise<IPAddress> promise) {
|
||||
if (host.empty()) {
|
||||
return promise.set_error(Status::Error("Host is empty"));
|
||||
}
|
||||
|
||||
auto r_ascii_host = idn_to_ascii(host);
|
||||
if (r_ascii_host.is_error()) {
|
||||
return promise.set_error(r_ascii_host.move_as_error());
|
||||
}
|
||||
auto ascii_host = r_ascii_host.move_as_ok();
|
||||
if (ascii_host.empty()) {
|
||||
return promise.set_error(Status::Error("Host is empty"));
|
||||
}
|
||||
|
||||
auto begin_time = Time::now();
|
||||
auto &value = cache_[prefer_ipv6].emplace(ascii_host, Value{{}, begin_time - 1.0}).first->second;
|
||||
|
@ -9,11 +9,11 @@
|
||||
#include "td/actor/actor.h"
|
||||
#include "td/actor/PromiseFuture.h"
|
||||
|
||||
#include "td/utils/FlatHashMap.h"
|
||||
#include "td/utils/logging.h"
|
||||
#include "td/utils/port/IPAddress.h"
|
||||
#include "td/utils/Status.h"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
|
||||
namespace td {
|
||||
@ -56,7 +56,7 @@ class GetHostByNameActor final : public Actor {
|
||||
return result;
|
||||
}
|
||||
};
|
||||
std::unordered_map<string, Value> cache_[2];
|
||||
FlatHashMap<string, Value> cache_[2];
|
||||
|
||||
struct Query {
|
||||
ActorOwn<> query;
|
||||
@ -65,7 +65,7 @@ class GetHostByNameActor final : public Actor {
|
||||
double begin_time = 0.0;
|
||||
std::vector<std::pair<int, Promise<IPAddress>>> promises;
|
||||
};
|
||||
std::unordered_map<string, Query> active_queries_[2];
|
||||
FlatHashMap<string, Query> active_queries_[2];
|
||||
|
||||
Options options_;
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#if !TD_EMSCRIPTEN
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/crypto.h"
|
||||
#include "td/utils/FlatHashMap.h"
|
||||
#include "td/utils/logging.h"
|
||||
#include "td/utils/misc.h"
|
||||
#include "td/utils/port/IPAddress.h"
|
||||
@ -26,7 +27,6 @@
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
#if TD_PORT_WINDOWS
|
||||
#include <wincrypt.h>
|
||||
@ -130,7 +130,7 @@ int verify_callback(int preverify_ok, X509_STORE_CTX *ctx) {
|
||||
static std::mutex warning_mutex;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(warning_mutex);
|
||||
static std::unordered_map<std::string, double> next_warning_time;
|
||||
static FlatHashMap<string, double> next_warning_time;
|
||||
double &next = next_warning_time[warning];
|
||||
if (next <= now) {
|
||||
next = now + 300; // one warning per 5 minutes
|
||||
|
@ -6,6 +6,7 @@
|
||||
//
|
||||
#include "td/utils/OptionParser.h"
|
||||
|
||||
#include "td/utils/FlatHashMap.h"
|
||||
#include "td/utils/logging.h"
|
||||
#include "td/utils/PathView.h"
|
||||
#include "td/utils/SliceBuilder.h"
|
||||
@ -16,8 +17,6 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#if TD_PORT_WINDOWS
|
||||
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
|
||||
#include <shellapi.h>
|
||||
@ -96,8 +95,8 @@ Result<vector<char *>> OptionParser::run(int argc, char *argv[], int expected_no
|
||||
}
|
||||
|
||||
Result<vector<char *>> OptionParser::run_impl(int argc, char *argv[], int expected_non_option_count) {
|
||||
std::unordered_map<char, const Option *> short_options;
|
||||
std::unordered_map<string, const Option *> long_options;
|
||||
FlatHashMap<char, const Option *> short_options;
|
||||
FlatHashMap<string, const Option *> long_options;
|
||||
for (auto &opt : options_) {
|
||||
if (opt.short_key != '\0') {
|
||||
short_options[opt.short_key] = &opt;
|
||||
|
@ -7,17 +7,17 @@
|
||||
#include "td/utils/translit.h"
|
||||
|
||||
#include "td/utils/algorithm.h"
|
||||
#include "td/utils/FlatHashMap.h"
|
||||
#include "td/utils/misc.h"
|
||||
#include "td/utils/utf8.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
|
||||
namespace td {
|
||||
|
||||
static const std::unordered_map<uint32, string> &get_en_to_ru_simple_rules() {
|
||||
static const std::unordered_map<uint32, string> rules{
|
||||
static const FlatHashMap<uint32, string> &get_en_to_ru_simple_rules() {
|
||||
static const FlatHashMap<uint32, string> rules{
|
||||
{'a', "а"}, {'b', "б"}, {'c', "к"}, {'d', "д"}, {'e', "е"}, {'f', "ф"}, {'g', "г"}, {'h', "х"}, {'i', "и"},
|
||||
{'j', "й"}, {'k', "к"}, {'l', "л"}, {'m', "м"}, {'n', "н"}, {'o', "о"}, {'p', "п"}, {'q', "к"}, {'r', "р"},
|
||||
{'s', "с"}, {'t', "т"}, {'u', "у"}, {'v', "в"}, {'w', "в"}, {'x', "кс"}, {'y', "и"}, {'z', "з"}};
|
||||
@ -32,8 +32,8 @@ static const std::vector<std::pair<string, string>> &get_en_to_ru_complex_rules(
|
||||
return rules;
|
||||
}
|
||||
|
||||
static const std::unordered_map<uint32, string> &get_ru_to_en_simple_rules() {
|
||||
static const std::unordered_map<uint32, string> rules{
|
||||
static const FlatHashMap<uint32, string> &get_ru_to_en_simple_rules() {
|
||||
static const FlatHashMap<uint32, string> rules{
|
||||
{0x430, "a"}, {0x431, "b"}, {0x432, "v"}, {0x433, "g"}, {0x434, "d"}, {0x435, "e"}, {0x451, "e"},
|
||||
{0x436, "zh"}, {0x437, "z"}, {0x438, "i"}, {0x439, "y"}, {0x43a, "k"}, {0x43b, "l"}, {0x43c, "m"},
|
||||
{0x43d, "n"}, {0x43e, "o"}, {0x43f, "p"}, {0x440, "r"}, {0x441, "s"}, {0x442, "t"}, {0x443, "u"},
|
||||
@ -49,8 +49,8 @@ static const std::vector<std::pair<string, string>> &get_ru_to_en_complex_rules(
|
||||
}
|
||||
|
||||
static void add_word_transliterations(vector<string> &result, Slice word, bool allow_partial,
|
||||
const std::unordered_map<uint32, string> &simple_rules,
|
||||
const std::vector<std::pair<string, string>> &complex_rules) {
|
||||
const FlatHashMap<uint32, string> &simple_rules,
|
||||
const vector<std::pair<string, string>> &complex_rules) {
|
||||
string s;
|
||||
auto pos = word.ubegin();
|
||||
auto end = word.uend();
|
||||
|
Loading…
Reference in New Issue
Block a user