Skip to content

Commit 86bceb2

Browse files
committed
td: replace most of std::unordered_map usages to td::FlatHashMap
1 parent 088ce02 commit 86bceb2

65 files changed

Lines changed: 377 additions & 361 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎td/telegram/AnimationsManager.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "td/utils/common.h"
2121
#include "td/utils/Status.h"
2222

23-
#include <unordered_map>
23+
#include "td/utils/FlatHashMap.h"
2424

2525
namespace td {
2626

@@ -142,7 +142,7 @@ class AnimationsManager final : public Actor {
142142
Td *td_;
143143
ActorShared<> parent_;
144144

145-
std::unordered_map<FileId, unique_ptr<Animation>, FileIdHash> animations_;
145+
FlatHashMap<FileId, unique_ptr<Animation>, FileIdHash> animations_;
146146

147147
int32 saved_animations_limit_ = 200;
148148
vector<FileId> saved_animation_ids_;

‎td/telegram/AudiosManager.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "td/utils/buffer.h"
1616
#include "td/utils/common.h"
1717

18-
#include <unordered_map>
18+
#include "td/utils/FlatHashMap.h"
1919

2020
namespace td {
2121

@@ -75,7 +75,7 @@ class AudiosManager {
7575
FileId on_get_audio(unique_ptr<Audio> new_audio, bool replace);
7676

7777
Td *td_;
78-
std::unordered_map<FileId, unique_ptr<Audio>, FileIdHash> audios_;
78+
FlatHashMap<FileId, unique_ptr<Audio>, FileIdHash> audios_;
7979
};
8080

8181
} // namespace td

‎td/telegram/BackgroundManager.h‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "td/utils/Status.h"
2323

2424
#include <memory>
25-
#include <unordered_map>
25+
#include "td/utils/FlatHashMap.h"
2626
#include <unordered_set>
2727
#include <utility>
2828

@@ -160,17 +160,17 @@ class BackgroundManager final : public Actor {
160160
void do_upload_background_file(FileId file_id, const BackgroundType &type, bool for_dark_theme,
161161
tl_object_ptr<telegram_api::InputFile> &&input_file, Promise<Unit> &&promise);
162162

163-
std::unordered_map<BackgroundId, Background, BackgroundIdHash> backgrounds_;
163+
FlatHashMap<BackgroundId, Background, BackgroundIdHash> backgrounds_;
164164

165-
std::unordered_map<BackgroundId, std::pair<int64, FileSourceId>, BackgroundIdHash>
165+
FlatHashMap<BackgroundId, std::pair<int64, FileSourceId>, BackgroundIdHash>
166166
background_id_to_file_source_id_; // id -> [access_hash, file_source_id]
167167

168-
std::unordered_map<string, BackgroundId> name_to_background_id_;
168+
FlatHashMap<string, BackgroundId> name_to_background_id_;
169169

170-
std::unordered_map<FileId, BackgroundId, FileIdHash> file_id_to_background_id_;
170+
FlatHashMap<FileId, BackgroundId, FileIdHash> file_id_to_background_id_;
171171

172172
std::unordered_set<string> loaded_from_database_backgrounds_;
173-
std::unordered_map<string, vector<Promise<Unit>>> being_loaded_from_database_backgrounds_;
173+
FlatHashMap<string, vector<Promise<Unit>>> being_loaded_from_database_backgrounds_;
174174

175175
BackgroundId set_background_id_[2];
176176
BackgroundType set_background_type_[2];
@@ -190,7 +190,7 @@ class BackgroundManager final : public Actor {
190190
: type_(type), for_dark_theme_(for_dark_theme), promise_(std::move(promise)) {
191191
}
192192
};
193-
std::unordered_map<FileId, UploadedFileInfo, FileIdHash> being_uploaded_files_;
193+
FlatHashMap<FileId, UploadedFileInfo, FileIdHash> being_uploaded_files_;
194194

195195
BackgroundId max_local_background_id_;
196196
vector<BackgroundId> local_background_ids_[2];

‎td/telegram/CallManager.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "td/utils/Status.h"
1818

1919
#include <map>
20-
#include <unordered_map>
20+
#include "td/utils/FlatHashMap.h"
2121

2222
namespace td {
2323

@@ -48,7 +48,7 @@ class CallManager final : public Actor {
4848
};
4949
std::map<int64, CallInfo> call_info_;
5050
int32 next_call_id_{1};
51-
std::unordered_map<CallId, ActorOwn<CallActor>, CallIdHash> id_to_actor_;
51+
FlatHashMap<CallId, ActorOwn<CallActor>, CallIdHash> id_to_actor_;
5252

5353
ActorId<CallActor> get_call_actor(CallId call_id);
5454
CallId create_call_actor();

‎td/telegram/Client.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <memory>
3030
#include <mutex>
3131
#include <queue>
32-
#include <unordered_map>
32+
#include "td/utils/FlatHashMap.h"
3333
#include <unordered_set>
3434

3535
namespace td {
@@ -205,7 +205,7 @@ class ClientManager::Impl final {
205205
ClientId client_id_{0};
206206
Td::Options options_;
207207
std::unordered_set<int32> pending_clients_;
208-
std::unordered_map<int32, ActorOwn<Td>> tds_;
208+
FlatHashMap<int32, ActorOwn<Td>> tds_;
209209
};
210210

211211
class Client::Impl final {
@@ -264,7 +264,7 @@ class MultiTd final : public Actor {
264264

265265
private:
266266
Td::Options options_;
267-
std::unordered_map<int32, ActorOwn<Td>> tds_;
267+
FlatHashMap<int32, ActorOwn<Td>> tds_;
268268
};
269269

270270
class TdReceiver {
@@ -580,7 +580,7 @@ class ClientManager::Impl final {
580580
std::shared_ptr<MultiImpl> impl;
581581
bool is_closed = false;
582582
};
583-
std::unordered_map<ClientId, MultiImplInfo> impls_;
583+
FlatHashMap<ClientId, MultiImplInfo> impls_;
584584
TdReceiver receiver_;
585585
};
586586

‎td/telegram/ClientJson.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static ClientManager *get_manager() {
119119
}
120120

121121
static std::mutex extra_mutex;
122-
static std::unordered_map<int64, string> extra;
122+
static FlatHashMap<int64, string> extra;
123123
static std::atomic<uint64> extra_id{1};
124124

125125
int json_create_client_id() {

‎td/telegram/ClientJson.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <cstdint>
1515
#include <mutex>
1616
#include <string>
17-
#include <unordered_map>
17+
#include "td/utils/FlatHashMap.h"
1818

1919
namespace td {
2020

@@ -30,7 +30,7 @@ class ClientJson final {
3030
private:
3131
Client client_;
3232
std::mutex mutex_; // for extra_
33-
std::unordered_map<std::int64_t, std::string> extra_;
33+
FlatHashMap<std::int64_t, std::string> extra_;
3434
std::atomic<std::uint64_t> extra_id_{1};
3535
};
3636

‎td/telegram/ConfigManager.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363

6464
#include <functional>
6565
#include <memory>
66-
#include <unordered_map>
66+
#include "td/utils/FlatHashMap.h"
6767
#include <utility>
6868

6969
namespace td {
@@ -1495,8 +1495,8 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
14951495
vector<tl_object_ptr<telegram_api::jsonObjectValue>> new_values;
14961496
string ignored_restriction_reasons;
14971497
vector<string> dice_emojis;
1498-
std::unordered_map<string, size_t> dice_emoji_index;
1499-
std::unordered_map<string, string> dice_emoji_success_value;
1498+
FlatHashMap<string, size_t> dice_emoji_index;
1499+
FlatHashMap<string, string> dice_emoji_success_value;
15001500
vector<string> emoji_sounds;
15011501
string animation_search_provider;
15021502
string animation_search_emojis;

‎td/telegram/ConfigShared.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ string ConfigShared::get_option(Slice name) const {
5858
return config_pmc_->get(name.str());
5959
}
6060

61-
std::unordered_map<string, string> ConfigShared::get_options() const {
61+
FlatHashMap<string, string> ConfigShared::get_options() const {
6262
return config_pmc_->get_all();
6363
}
6464

‎td/telegram/ConfigShared.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "td/utils/Slice.h"
1313

1414
#include <memory>
15-
#include <unordered_map>
15+
#include "td/utils/FlatHashMap.h"
1616

1717
namespace td {
1818

@@ -42,7 +42,7 @@ class ConfigShared {
4242

4343
string get_option(Slice name) const;
4444

45-
std::unordered_map<string, string> get_options() const;
45+
FlatHashMap<string, string> get_options() const;
4646

4747
bool get_option_boolean(Slice name, bool default_value = false) const;
4848
int64 get_option_integer(Slice name, int64 default_value = 0) const;

0 commit comments

Comments
 (0)