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();
|
||||
for (const auto &name_value : all_options) {
|
||||
const string &name = name_value.first;
|
||||
CHECK(!name.empty());
|
||||
options_->set(name, name_value.second);
|
||||
if (!is_internal_option(name)) {
|
||||
send_closure(G()->td(), &Td::send_update,
|
||||
|
@ -6,11 +6,9 @@
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/utils/HashTableUtils.h"
|
||||
#include "td/utils/FlatHashMap.h"
|
||||
#include "td/utils/Slice.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace td {
|
||||
|
||||
class SeqKeyValue {
|
||||
@ -24,6 +22,7 @@ class SeqKeyValue {
|
||||
~SeqKeyValue() = default;
|
||||
|
||||
SeqNo set(Slice key, Slice value) {
|
||||
CHECK(!key.empty());
|
||||
auto it_ok = map_.emplace(key.str(), value.str());
|
||||
if (!it_ok.second) {
|
||||
if (it_ok.first->second == value) {
|
||||
@ -84,13 +83,19 @@ class SeqKeyValue {
|
||||
return map_.size();
|
||||
}
|
||||
|
||||
std::unordered_map<string, string, Hash<string>> get_all() const {
|
||||
return map_;
|
||||
FlatHashMap<string, string> get_all() const {
|
||||
FlatHashMap<string, string> result;
|
||||
result.reserve(map_.size());
|
||||
for (auto &it : map_) {
|
||||
result.emplace(it.first, it.second);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<string, string, Hash<string>> map_;
|
||||
FlatHashMap<string, string> map_;
|
||||
SeqNo current_id_ = 0;
|
||||
|
||||
SeqNo next_seq_no() {
|
||||
return ++current_id_;
|
||||
}
|
||||
|
@ -8,11 +8,10 @@
|
||||
|
||||
#include "td/db/SeqKeyValue.h"
|
||||
|
||||
#include "td/utils/HashTableUtils.h"
|
||||
#include "td/utils/FlatHashMap.h"
|
||||
#include "td/utils/port/RwMutex.h"
|
||||
#include "td/utils/Slice.h"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
|
||||
namespace td {
|
||||
@ -69,7 +68,7 @@ class TsSeqKeyValue {
|
||||
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();
|
||||
return kv_.get_all();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user