Use FlatHashMap in SeqKeyValue.
This commit is contained in:
parent
1fbbecca9b
commit
0a7c87eb8b
@ -60,6 +60,7 @@ OptionManager::OptionManager(Td *td)
|
|||||||
all_options["utc_time_offset"] = PSTRING() << 'I' << Clocks::tz_offset();
|
all_options["utc_time_offset"] = PSTRING() << 'I' << Clocks::tz_offset();
|
||||||
for (const auto &name_value : all_options) {
|
for (const auto &name_value : all_options) {
|
||||||
const string &name = name_value.first;
|
const string &name = name_value.first;
|
||||||
|
CHECK(!name.empty());
|
||||||
options_->set(name, name_value.second);
|
options_->set(name, name_value.second);
|
||||||
if (!is_internal_option(name)) {
|
if (!is_internal_option(name)) {
|
||||||
send_closure(G()->td(), &Td::send_update,
|
send_closure(G()->td(), &Td::send_update,
|
||||||
|
@ -6,11 +6,9 @@
|
|||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "td/utils/HashTableUtils.h"
|
#include "td/utils/FlatHashMap.h"
|
||||||
#include "td/utils/Slice.h"
|
#include "td/utils/Slice.h"
|
||||||
|
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
class SeqKeyValue {
|
class SeqKeyValue {
|
||||||
@ -24,6 +22,7 @@ class SeqKeyValue {
|
|||||||
~SeqKeyValue() = default;
|
~SeqKeyValue() = default;
|
||||||
|
|
||||||
SeqNo set(Slice key, Slice value) {
|
SeqNo set(Slice key, Slice value) {
|
||||||
|
CHECK(!key.empty());
|
||||||
auto it_ok = map_.emplace(key.str(), value.str());
|
auto it_ok = map_.emplace(key.str(), value.str());
|
||||||
if (!it_ok.second) {
|
if (!it_ok.second) {
|
||||||
if (it_ok.first->second == value) {
|
if (it_ok.first->second == value) {
|
||||||
@ -84,13 +83,19 @@ class SeqKeyValue {
|
|||||||
return map_.size();
|
return map_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unordered_map<string, string, Hash<string>> get_all() const {
|
FlatHashMap<string, string> get_all() const {
|
||||||
return map_;
|
FlatHashMap<string, string> result;
|
||||||
|
result.reserve(map_.size());
|
||||||
|
for (auto &it : map_) {
|
||||||
|
result.emplace(it.first, it.second);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<string, string, Hash<string>> map_;
|
FlatHashMap<string, string> map_;
|
||||||
SeqNo current_id_ = 0;
|
SeqNo current_id_ = 0;
|
||||||
|
|
||||||
SeqNo next_seq_no() {
|
SeqNo next_seq_no() {
|
||||||
return ++current_id_;
|
return ++current_id_;
|
||||||
}
|
}
|
||||||
|
@ -8,11 +8,10 @@
|
|||||||
|
|
||||||
#include "td/db/SeqKeyValue.h"
|
#include "td/db/SeqKeyValue.h"
|
||||||
|
|
||||||
#include "td/utils/HashTableUtils.h"
|
#include "td/utils/FlatHashMap.h"
|
||||||
#include "td/utils/port/RwMutex.h"
|
#include "td/utils/port/RwMutex.h"
|
||||||
#include "td/utils/Slice.h"
|
#include "td/utils/Slice.h"
|
||||||
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
@ -69,7 +68,7 @@ class TsSeqKeyValue {
|
|||||||
return kv_.size();
|
return kv_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unordered_map<string, string, Hash<string>> get_all() const {
|
FlatHashMap<string, string> get_all() const {
|
||||||
auto lock = rw_mutex_.lock_write().move_as_ok();
|
auto lock = rw_mutex_.lock_write().move_as_ok();
|
||||||
return kv_.get_all();
|
return kv_.get_all();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user