Skip to content

Commit dc6b9dd

Browse files
futpibjohn-preston
authored andcommitted
Use faster containers for bulk-populated custom emoji maps
Replace base::flat_map (sorted vector with O(n) insertion) with std::unordered_map for CustomEmojiManager::_instances and std::map for EmojiListWidget::_customEmoji. These maps accumulate ~8000 entries during startup with unsorted keys, causing O(n²) total insertion cost. This change reduces refreshCustom() from ~3s to ~50ms (57x speedup).
1 parent f9bf1e9 commit dc6b9dd

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

Telegram/SourceFiles/chat_helpers/emoji_list_widget.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ For license and copyright information please follow this link:
1313
#include "ui/round_rect.h"
1414
#include "base/timer.h"
1515

16+
#include <map>
17+
1618
class StickerPremiumMark;
1719

1820
namespace style {
@@ -438,7 +440,7 @@ class EmojiListWidget final
438440
QVector<EmojiPtr> _emoji[kEmojiSectionCount];
439441
std::vector<CustomSet> _custom;
440442
base::flat_set<DocumentId> _restrictedCustomList;
441-
base::flat_map<EmojiStatusId, CustomEmojiInstance> _customEmoji;
443+
std::map<EmojiStatusId, CustomEmojiInstance> _customEmoji;
442444
base::flat_map<
443445
DocumentId,
444446
std::unique_ptr<Ui::Text::CustomEmoji>> _customRecent;

Telegram/SourceFiles/data/stickers/data_custom_emoji.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class CustomEmojiManager final : public base::has_weak_ptr {
149149
const not_null<Session*> _owner;
150150

151151
std::array<
152-
base::flat_map<
152+
std::unordered_map<
153153
DocumentId,
154154
std::unique_ptr<Ui::CustomEmoji::Instance>>,
155155
kSizeCount> _instances;

0 commit comments

Comments
 (0)